Last active
June 20, 2019 16:57
-
-
Save celsowm/1db2d058bfaafff87d4dfbc13378eec5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS teste; | |
CREATE SEQUENCE teste_seq; | |
CREATE TABLE IF NOT EXISTS teste ( | |
id bigint NOT NULL DEFAULT NEXTVAL ('teste_seq'), | |
datetime timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP, | |
channel int DEFAULT NULL, | |
value double precision DEFAULT NULL, | |
PRIMARY KEY (id) | |
) ; | |
ALTER SEQUENCE teste_seq RESTART WITH 1000001; | |
CREATE OR REPLACE PROCEDURE generate_data() | |
LANGUAGE plpgsql | |
AS $$ | |
DECLARE result INTEGER = 0; | |
BEGIN | |
WHILE result != 1000000 LOOP | |
INSERT INTO teste | |
( datetime, value, channel ) | |
VALUES ( NOW() - '1 year'::INTERVAL * ROUND(RANDOM() * 100), ROUND(RANDOM() * 100, 2), 1 ); | |
result := result + 1; | |
END LOOP; | |
COMMIT; | |
END; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment