A column for which a value will be specified. The name must match a column table, though these columns need not be listed in their literal order within the table.
value
A constant or expression to insert into a column within table. This value is associated with the corresponding column in the column list if a column list was specified (columns in the column list correspond in a one-to-one fashion with expressions in the value list). If the expression for each column is not of the correct data type, automatic type coercion will be attempted. If this fails, the INSERT will fail completely.
query
A valid SQL SELECT statement. The number of columns returned by the query must match the number of columns you are inserting, as well as be of a compatible data type.
Results
INSERToid 1
The message returned if one row of data is inserted correctly. The oid is the object identifier of the newly inserted row.
INSERT0 #
The message returned if more than one row is inserted. The # symbol represents how many rows were updated in total.
Description
Use the INSERT command to add new rows into a table. This can be done either one row at a time, or in sets. Used with the VALUES keyword, an INSERT statement can only insert one row of data. To insert multiple rows, you can instead supply a query. Results from the query are then fed into the INSERT command's target table.
If an incorrect data type is provided for a field on insertion, PostgreSQL will attempt to automatically coerce it into the appropriate type. If it cannot, the INSERT will fail.
When inserting values into columns (instead of whole rows), the columns can be listed in any order; however, the values for those columns will need to be listed in the same order.
Note: If you leave out values for any fields in your table, the database will automatically do one of two things. Fields for which you have not specified a default value will be set to NULL. Fields for which you have specified a default value will be set to their defaults.
Examples
The following example inserts a single row into the employees table:
Alternatively, you can insert only an ID number and last name, and not a first name, by specifying a target column list preceding the VALUES clause. This results in a NULL value for the first_name column in the new row: