Created
September 11, 2014 17:43
-
-
Save lesovsky/3afe023b1843683adee6 to your computer and use it in GitHub Desktop.
insert_test_data.sql
This file contains 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 function if exists insert_test_data(bigint,bigint,bigint); | |
create or replace function insert_test_data(bigint,bigint,bigint) returns void as $$ | |
declare | |
seq_start bigint := $1; | |
seq_end bigint := $2; | |
interval constant bigint := $3; | |
step bigint := interval; | |
begin | |
while (seq_start - 1) != seq_end loop | |
insert into products select | |
generate_series(seq_start,step) as id, | |
md5(random()::text)::char(10) as name, | |
(random()*1000)::numeric(10,2) as price, | |
(random() * 21 + 22)::int as size, | |
(array['cyan','magenta','yellow','black'])[ceil(random()*4)] as color, | |
(now() - interval '1 day' * round(random()*100))::timestamp(0) as updated_at, | |
(now() - interval '2 year' + interval '1 year' * random())::date as built, | |
random()::int::bool as is_available; | |
raise notice 'inserted % rows', step; | |
seq_start := seq_start + interval; | |
step := seq_start + interval - 1; | |
end loop; | |
end; | |
$$ language plpgsql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment