Create n rows from NULL in PostgreSQL

I have a table that looks like this:

id, integer, Primary Key, not null name, character varying created, timestamp without timezone, not null, default: now() 

I want to generate n lines with a NULL field name.

I know what I can do:

 INSERT INTO employee (name) VALUES (NULL), (NULL)... 

But I would rather do something like this:

 INSERT INTO employee (name) SELECT NULL FROM dummy_table_with_n_rows 

And I could choose n.

+6
source share
1 answer
 INSERT INTO employee (name) SELECT NULL FROM generate_series(1,10000) i; 
+16
source

Source: https://habr.com/ru/post/945097/


All Articles