17

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 rows with NULL a name field.

I know that I can do:

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

But I'd prefer to do something like this:

INSERT INTO
  employee (name)
SELECT
  NULL
FROM
  dummy_table_with_n_rows

And I would be able to choose the n.

1 Answer 1

36
INSERT INTO
  employee (name)
SELECT
  NULL 
FROM
  generate_series(1,10000) i;
Sign up to request clarification or add additional context in comments.

1 Comment

@DanielPatz: Don't miss the variations of the function too. Some are quite neat: postgresql.org/docs/9.2/static/functions-srf.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.