DEV Community

Discussion on: Using Postgres FOR loop to generate data

Collapse
 
buinauskas profile image
Evaldas Buinauskas

How about this?

INSERT INTO items(name, active)
SELECT 'Test item ' || a.n, true
FROM generate_series(1, 100) as a(n)

SQL works much much better with set based operators than classic loops.

Obviously for 100 rows it won't make a noticeable difference 🙂