INSERT
Last updated
Last updated
Use INSERT for both single- and multi-row ad hoc inserts. (When inserting many rows, use the more efficient command.)
You can also insert into a table as SELECT, as shown in the following examples:
You can insert array literals into array columns. The inserts in the following example each have three array values, and demonstrate how you can:
Create a table with variable-length and fixed-length array columns.
Insert NULL
arrays into these colums.
Specify and insert array literals using {...}
or ARRAY[...]
syntax.
Insert empty variable-length arrays using{}
and ARRAY[]
syntax.
Insert array values that contain NULL
elements.
If you omit the name column from an INSERT or INSERT FROM SELECT statement, the missing value for column name
is set to 'John Doe'
.
INSERT INTO tbl (id, age) VALUES (1, 36);
creates the record 1|'John Doe'|36
.
INSERT INTO tbl (id, age) SELECT id, age FROM old_tbl;
also sets all the name values to John Doe
.
If you with column that has a default value, or to add a column with a default value, using the INSERT command creates a record that includes the default value if it is omitted from the INSERT. For example, assume a table created as follows: