INSERT
The SQL statement that adds new rows to a table.
In more detail
Always list the columns you are filling, so the statement keeps working when the table gains a column. Pass values as bound parameters, let constraints reject bad rows, and read back the new row, with RETURNING or a follow-up SELECT.
Example
INSERT INTO customers (id, name, city, country, joined) VALUES (7, 'Farah Bello', 'Kano', 'NG', '2025-01-10');Related terms
- prepared statement — A SQL statement with placeholders, such as ?, whose values are sent separately from the SQL text instead of pasted into it.
- constraint — A rule the database enforces on stored data, such as a column that must be unique or not null.
- RETURNING — A clause on INSERT, UPDATE or DELETE that returns the rows it wrote, such as the id of a new row.
- DEFAULT — A column clause giving the value the database stores when an insert does not supply one.
Taught in
- Why Tables And Relations Beat Files — PostgreSQL, Indexing & Relational Data Modeling
- Keys, Constraints And Referential Integrity — PostgreSQL, Indexing & Relational Data Modeling
- Inserting Data Safely — PostgreSQL, Indexing & Relational Data Modeling