2013-05-15 23 views
6

NULL的n行我有一个表,看起来像这样:产生的PostgreSQL

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

我想生成NULL名称字段n行。

我知道我能做到:

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

但我更愿意做这样的事情:

INSERT INTO 
    employee (name) 
SELECT 
    NULL 
FROM 
    dummy_table_with_n_rows 

而且我能够选择n个。

回答

16
INSERT INTO 
    employee (name) 
SELECT 
    NULL 
FROM 
    generate_series(1,10000) i; 
+0

正是我在找的东西! –

+3

@DanielPatz:不要错过功能的变化。有些非常整洁:http://www.postgresql.org/docs/9.2/static/functions-srf.html –