Skip to content

Instantly share code, notes, and snippets.

@celsowm
Last active June 20, 2019 16:57
Show Gist options
  • Save celsowm/1db2d058bfaafff87d4dfbc13378eec5 to your computer and use it in GitHub Desktop.
Save celsowm/1db2d058bfaafff87d4dfbc13378eec5 to your computer and use it in GitHub Desktop.
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