How to insert data in postgresql using for loop?
Please try below code to insert values in tables using for loop. do $$ begin for r in 1..1000 loop insert into schema_name.table_name(id) values(r); end loop; end; $$;
Please try below code to insert values in tables using for loop. do $$ begin for r in 1..1000 loop insert into schema_name.table_name(id) values(r); end loop; end; $$;
You could cross join it to a series of 3: SELECT a.n from generate_series(1, 100) as a(n), generate_series(1, 3)
DO command vs. PL/pgSQL function A DO command does not return rows. You can send NOTICES or RAISE other messages (using default LANGUAGE plpgsql), or you can write to a (temporary) table and later SELECT from it to get around this. But really, create a function instead, where you can define a return type with … Read more
Can be done without conversion to/from int (but to/from timestamp instead) SELECT date_trunc(‘day’, dd):: date FROM generate_series ( ‘2007-02-01’::timestamp , ‘2008-04-01’::timestamp , ‘1 day’::interval) dd ;