Coding⏱️ 2 min read📅 2026-06-03

How to Fix: PostgreSQL INSERT ON CONFLICT UPDATE (upsert) use all excluded values

Use all excluded values in PostgreSQL upsert with ON CONFLICT UPDATE

Quick Answer: Use the following syntax to insert and update using all excluded values: INSERT INTO tablename (id, username, password, level, email) VALUES (1, 'John', 'qwerty', 5, 'john@mail.com') ON CONFLICT (id) DO UPDATE SET id=EXCLUDED.id, username=EXCLUDED.username, password=EXCLUDED.password, level=EXCLUDED.level, email=EXCLUDED.email

When using PostgreSQL's INSERT ON CONFLICT UPDATE (upsert) feature, you may have noticed that the syntax can be a bit verbose. The question is, can you use all excluded values in a shorter way?

🔍 Why This Happens

  • The reason for this is that the EXCLUDED table contains all columns from the original table, including any unique constraints or indexes. By specifying each column individually in your UPDATE SET clause, you are ensuring that all values are updated correctly.

🚀 How to Resolve This Issue

Method 1: Using EXCLUDED.*

  1. Step 1: Replace each column name in the UPDATE SET clause with EXCLUDED.column_name, such as id=EXCLUDED.id, username=EXCLUDED.username, etc.

Method 2: Using ALL

  1. Step 1: Replace the UPDATE SET clause with EXCLUDED.*, which will update all columns from the EXCLUDED table.

🎯 Final Words

By using EXCLUDED.* or ALL, you can simplify your INSERT ON CONFLICT UPDATE (upsert) syntax and make it more readable. However, be aware that using ALL may have performance implications if the table has many columns.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions