Skip to content

Instantly share code, notes, and snippets.

@yihyang
Last active June 30, 2018 16:20
Show Gist options
  • Select an option

  • Save yihyang/cb61f0b2f4f6b41c43faff67f64619a0 to your computer and use it in GitHub Desktop.

Select an option

Save yihyang/cb61f0b2f4f6b41c43faff67f64619a0 to your computer and use it in GitHub Desktop.
SQL CheatSheet
# FOR LOOP - SQL
do $$
begin
for r in 1..100000 loop
insert into events(id,location_id, status) values(r,1,'ACTIVE');
end loop;
end;
$$;
# LOOP INSERT
INSERT INTO public.events(location_id, number_of_hosts)
SELECT id AS location_id, 10 AS number_of_hosts, FROM events ORDER BY id ASC LIMIT 1 OFFSET 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment