Re: COPY ON_CONFLICT TABLE; save duplicated record to another table.

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY ON_CONFLICT TABLE; save duplicated record to another table.
Date: 2026-05-11 20:40:18
Message-ID: CAN4CZFMRz4BY7booXLVNP3zvekAac8M5oQ6Oc5=tgxpYHkEPQg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello!

> One other thing I just noticed in BINARY mode. I believe we're missing a
> check in ProcessCopyOptions() with ON_CONFLICT TABLE to show a proper
> error message, e.g.

It is possible to crash the current patch with binary mode, that check
is definitely needed.

+ MakeTransitionCaptureState(cstate->conflictRel->trigdesc,
+ RelationGetRelid(cstate->conflictRel),
+ CMD_INSERT);

Shouldn't this update mtstate->mt_transition_capture?

+ if (cstate->opts.on_conflict == ONCONFLICT_TABLE)
...
+ if (conflict_mstate->fireBSTriggers)
+ {
+ ExecBSInsertTriggers(conflict_mstate->ps.state,
conflict_mstate->rootResultRelInfo);
+
+ conflict_mstate->fireBSTriggers = false;
+ }
+

and

+ if (cstate->num_conflicts > 0)
+ {
...
+ /* Execute AFTER STATEMENT insertion triggers */
+ ExecASInsertTriggers(cstate->mtcontext->estate,
+ on_conflict_mtstate->rootResultRelInfo,
+ on_conflict_mtstate->mt_transition_capture);

* Doesn't statements typically fire triggers unconditionally? INSERT
ON CONFLICT DO NOTHING; fires BS+AS triggers even if it doesn't insert
any rows.
* Isn't firing a before statement trigger after some before/after row
triggers were already fired (for non conflicting rows) strange?

+ if (valid_col_count != 4)
+ errdetail_msg = _("The conflict_table is incomplete; exactly four
columns are required.");

if valid_col_count > 4, is it still incomplete, shouldn't the error
message change in that case?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Treat 2026-05-11 20:52:05 Re: 2026-05-14 release announcement draft
Previous Message Nikita Malakhov 2026-05-11 20:12:53 Re: SQL/JSON json_table plan clause