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.
Example - With INSERT StatementINSERT INTO contacts (first_name, last_name) SELECT first_name, last_name FROM employees WHERE employee_number IS NULL; This PostgreSQL IS NULL example will insert records into the contacts table where the employee_number contains a NULL value.
Generate a series of numbers in postgres by using the generate_series function. The function requires either 2 or 3 inputs. The first input, [start], is the starting point for generating your series. [ stop] is the value that the series will stop at. The series will stop once the values pass the [stop] value.
Answer: No, Each null value only uses one bit on disk. If your database table has 30 such default null fields, it would still only be 30 bits per row.
PostgreSQL – NULLIF() Function The NULLIF function returns a null value if argument_1 equals to argument_2, otherwise it returns argument_1.
INSERT INTO
employee (name)
SELECT
NULL
FROM
generate_series(1,10000) i;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With