| From: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
|---|---|
| To: | jian he <jian(dot)universality(at)gmail(dot)com> |
| Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: COPY ON_CONFLICT TABLE; save duplicated record to another table. |
| Date: | 2026-05-06 22:17:35 |
| Message-ID: | CAN4CZFPMJVKt-dwwE=h0W4LB286V0WnQJQoHSJomqJmmJf84RQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hello!
I tried the patch and found a few issues.
1. Two of them are null pointer dereference crashes, one with
partitioned tables:
CREATE TABLE part_t (a int PRIMARY KEY, b text) PARTITION BY RANGE (a);
CREATE TABLE part_t_p1 PARTITION OF part_t FOR VALUES FROM (0) TO (1000);
CREATE TABLE conflict_log (
rel oid,
file_name text,
line_no bigint,
raw_line text
);
INSERT INTO part_t VALUES (1, 'pre-existing');
COPY part_t (a, b) FROM stdin WITH (on_conflict 'table',
conflict_table 'conflict_log');
2 row-two
1 dup
3 row-three
\.
2. And another with repeateable reads:
CREATE TABLE t_rr (a int PRIMARY KEY, b text);
CREATE TABLE conflict_log (rel oid, fname text, ln bigint, raw text);
INSERT INTO t_rr VALUES (1, 'pre-committed');
BEGIN ISOLATION LEVEL REPEATABLE READ;
COPY t_rr FROM stdin WITH (on_conflict 'table', conflict_table 'conflict_log');
1 dup-row
\.
3. There's also a possible data loss scenario, reports 3 copied 0 actual:
CREATE TABLE conf_log (
relname oid,
fname text,
lineno bigint,
rawline text
);
CREATE TABLE no_idx_tgt (id int, payload text);
CREATE FUNCTION noop_trig() RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN
RETURN NEW;
END;
$$;
CREATE TRIGGER noop_before BEFORE INSERT ON no_idx_tgt
FOR EACH ROW EXECUTE FUNCTION noop_trig();
COPY no_idx_tgt (id, payload) FROM STDIN
WITH (ON_CONFLICT TABLE, CONFLICT_TABLE conf_log);
1 alpha
2 beta
3 gamma
\.
SELECT 'A: no_idx_tgt count' AS scenario, count(*) AS rows FROM no_idx_tgt;
SELECT 'A: conf_log count' AS scenario, count(*) AS rows FROM conf_log;
SELECT * FROM no_idx_tgt ORDER BY id;
4. Shouldn't the following error out?
CREATE TABLE t (a int PRIMARY KEY, b text);
COPY t TO '/dev/null' (ON_CONFLICT TABLE, CONFLICT_TABLE no_such_table);
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-05-06 22:54:58 | Re: [PATCH] Fix ProcKill lock-group vs procLatch recycle race |
| Previous Message | Nathan Bossart | 2026-05-06 21:47:15 | Re: bump minimum supported version of psql and pg_{dump,dumpall,upgrade} to v10 |