Inserting Multiple Rows
Objectives
By the end of this lesson, you should be able to:
- Insert several rows in a single
INSERTstatement - Explain why this is preferable to separate
INSERTstatements for each row
💡 Why this matters: Loading a batch of records one
INSERTat a time works, but it’s slower and more verbose than it needs to be. A single statement can add many rows at once.
⚠️ A note on verification: every statement and result in this lesson was run against a real, live PostgreSQL 18 database, using the
employeestable from Module 3.
Multiple VALUES
Separate each row’s values with a comma, inside its own parentheses:
INSERT INTO employees (first_name, last_name, email, department, salary) VALUES
('Jordan', 'Reyes', 'jordan.reyes@example.com', 'Sales', 62000),
('Priya', 'Shah', 'priya.shah@example.com', 'Marketing', 58000);
id | first_name | department | salary
----+------------+-------------+---------
2 | Jordan | Sales | 62000.00
3 | Priya | Marketing | 58000.00
This is one statement, not two, every row is validated and inserted together. The column list at the top applies to every row that follows, there’s no need to repeat it.
Why This Is Better Than One Row at a Time
Sending ten separate INSERT statements to add ten rows works, but each one is a separate round trip to the database. A single multi-row INSERT sends all ten rows together, faster, and shorter to write and read.
Try It
- Insert three new employees in a single
INSERTstatement. - Confirm all three were added by selecting from
employees. - Explain, in your own words, why a single multi-row
INSERTis generally preferable to several single-rowINSERTstatements.
Recap
- Separating rows with commas, each in its own parentheses, inserts several rows in one statement.
- The column list is written once and applies to every row.
- A multi-row
INSERTis faster and more concise than repeating single-rowINSERTstatements.
Next lesson: INSERT ... SELECT, populating a table from the result of a query instead of literal values.