8.25. INSERT

Synopsis

  1. INSERT INTO table_name [ ( column [, ... ] ) ] query

Description

Insert new rows into a table.

If the list of column names is specified, they must exactly match the listof columns produced by the query. Each column in the table not present in thecolumn list will be filled with a null value. Otherwise, if the list ofcolumns is not specified, the columns produced by the query must exactly matchthe columns in the table being inserted into.

Examples

Load additional rows into the orders table from the new_orders table:

  1. INSERT INTO orders
  2. SELECT * FROM new_orders;

Insert a single row into the cities table:

  1. INSERT INTO cities VALUES (1, 'San Francisco');

Insert multiple rows into the cities table:

  1. INSERT INTO cities VALUES (2, 'San Jose'), (3, 'Oakland');

Insert a single row into the nation table with the specified column list:

  1. INSERT INTO nation (nationkey, name, regionkey, comment)
  2. VALUES (26, 'POLAND', 3, 'no comment');

Insert a row without specifying the comment column.That column will be null:

  1. INSERT INTO nation (nationkey, name, regionkey)
  2. VALUES (26, 'POLAND', 3);

See Also

VALUES