A new table has no rows. INSERT adds them.
One row
sql
INSERT INTO suppliers (id, name, country)
VALUES (1, 'Kraken Supply Co', 'CA');INSERT INTO suppliersadd rows to this table(id, name, country)the columns you give values forVALUES (1, 'Kraken Supply Co', 'CA')one value per column, in the same order;end
- Write text and dates in single quotes:
'CA','2025-03-14'. Write numbers andtrue/falsewithout quotes. - The Result tab shows
1 row inserted.
Several rows in one statement
Put a comma between the rows:
sql
INSERT INTO suppliers (id, name, country)
VALUES (2, 'Golem Goods', 'US'),
(3, 'Tokyo Plush Works', 'JP');suppliers
| id | name | country |
|---|---|---|
| 1 | Kraken Supply Co | CA |
| 2 | Golem Goods | US |
| 3 | Tokyo Plush Works | JP |
The column list
- The list can name the columns in any order. The values follow the order of the list.
- A column that is not in the list gets NULL.
- You can leave out the list. Then the values follow the column order of the table, and you must give a value for every column. When someone adds a column to the table later, the statement fails. Always write the list.
When the database refuses a row
PostgreSQL checks each value against the type of its column. A value that does not fit stops the statement:
text
ERROR: invalid input syntax for type integer: "Rex"
ERROR: value too long for type character varying(20)
ERROR: numeric field overflow
ERROR: INSERT has more target columns than expressionsThe last error means: the list has more columns than the row has values.
A statement that fails changes nothing. When one row of a three-row INSERT is wrong, no row is added. Fix the value and run the whole statement again.