</>
Skip to content
PostgreSQL lessons (11/38)

PostgreSQL — Insert

Basic Insert

INSERT INTO users (name, email) 
VALUES ('John', 'john@example.com');

Multiple Rows

INSERT INTO users (name, email) 
VALUES 
    ('John', 'john@example.com'),
    ('Jane', 'jane@example.com'),
    ('Bob', 'bob@example.com');

Returning

INSERT INTO users (name, email) 
VALUES ('John', 'john@example.com')
RETURNING id, name;

Insert from Select

INSERT INTO users_backup (name, email)
SELECT name, email FROM users;

On Conflict

INSERT INTO users (name, email) 
VALUES ('John', 'john@example.com')
ON CONFLICT (email) 
DO UPDATE SET name = EXCLUDED.name;

With Default Values

INSERT INTO users (name) VALUES ('John');
-- email and created_at use defaults

Mini Practice

  1. Insert single row
  2. Insert multiple rows
  3. Use RETURNING
  4. Handle conflicts

Up Next

Continue with Select — querying data.

Related Topics

Frequently Asked Questions about Insert

What is Insert in PostgreSQL?

Insert is a fundamental concept in PostgreSQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Insert?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Insert.

Why is Insert important in PostgreSQL?

Insert is essential for PostgreSQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.