postgres-syntax-upsert-merge

Explain and demonstrate PostgreSQL UPSERT and MERGE syntax for conflict resolution.

Updated May 19, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/PostgreSQL-Claude-Skill-Package --skill postgres-syntax-upsert-merge
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-syntax-upsert-merge
Source: https://github.com/Impertio-Studio/PostgreSQL-Claude-Skill-Package/tree/main/skills/source/postgres-syntax/postgres-syntax-upsert-merge
Command: npx skills add https://github.com/Impertio-Studio/PostgreSQL-Claude-Skill-Package --skill postgres-syntax-upsert-merge

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides a comprehensive guide to writing efficient and correct UPSERT and MERGE operations in PostgreSQL, helping developers avoid common pitfalls and optimize their database interactions.

Core Features & Use Cases

  • UPSERT Guide: Learn the syntax and use cases for INSERT ... ON CONFLICT to perform idempotent inserts and updates.
  • MERGE Mastery: Understand the MERGE statement for complex data synchronization tasks and how to handle various conflict scenarios.
  • Use Case: For developers looking to implement robust data migration strategies or sync data between databases, this Skill offers essential knowledge to make informed decisions.

Quick Start

Use the postgres-syntax-upsert-merge skill to learn how to handle unique constraint violations in PostgreSQL with the UPSERT statement.

Frequently Asked Questions about postgres-syntax-upsert-merge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I perform an UPSERT in PostgreSQL to handle unique constraint violations?

To perform an UPSERT in PostgreSQL, use the INSERT ... ON CONFLICT statement to execute idempotent inserts and updates. This syntax automatically handles unique constraint violations by updating the existing row instead of throwing an error.

What is the MERGE statement in PostgreSQL used for?

The MERGE statement in PostgreSQL is used for complex data synchronization tasks, allowing you to perform atomic inserts, updates, and deletes with conflict resolution. It is ideal for handling various conflict scenarios during database migrations.

Does PostgreSQL MERGE syntax require a specific database version?

Yes, using the MERGE syntax and ON CONFLICT clause requires PostgreSQL 9.5 or later. You need knowledge of these specific features to execute atomic data operations and implement robust migration strategies correctly.

What is the best way to synchronize data between PostgreSQL databases atomically?

The best way to synchronize data atomically is by using the PostgreSQL MERGE statement. It manages complex data synchronization from a source to a target table, handling conditional updates and inserts within a single transaction.

When should I use ON CONFLICT versus MERGE for PostgreSQL data migrations?

Use ON CONFLICT for simpler idempotent inserts and updates based on unique constraints. Use MERGE for more complex data synchronization and migration strategies requiring conditional logic across multiple matched and unmatched scenarios.