RSS Amplifier

kubuzetto's blog · Aug 20, 2025

Writing ON CONFLICT Clauses on Partial Indexes using GORM

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

Introduction PostgreSQL’s ON CONFLICT clause is a useful construct that allows you to handle cases where an insertion may violate a uniqueness constraint. It is not standard SQL syntax, but an extension, like SQLite’s INSERT OR REPLACE . Let’s say we have a table named tasks like this: create table if not exists tasks ( account_id integer not null , task_name text not null ,…

Introduction

PostgreSQL’s ON CONFLICT clause is a useful construct that allows you to handle cases where an insertion may violate a uniqueness constraint. It is not standard SQL syntax, but an extension, like SQLite’s INSERT OR REPLACE.

Let’s say we have a table named tasks like this:

create table if not exists tasks
(
 account_id integer not null,
 task_name text not null,
 task_desc text not null
);
-- Yes, I prefer lowercase SQL. Sue me

Say we want tasks to have unique names for each account. Let’s define a unique index for it:

Read on /posts/go-partial-on-conflict/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.