#10689·timescaledb

[Bug]: INSERT ... ON CONFLICT DO UPDATE with a repeated key succeeds on a compressed chunk instead of raising SQLSTATE 21000

Author: cevianCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbugneeds-triagev2.31.0

What type of bug is this?

Incorrect result

What subsystems and features are affected?

Compression

What happened?

An INSERT ... ON CONFLICT DO UPDATE whose VALUES list contains the same conflict key twice is rejected by PostgreSQL, and by an uncompressed hypertable, with SQLSTATE 21000 ON CONFLICT DO UPDATE command cannot affect row a second time. When the conflicting row lives in a compressed chunk the same statement is accepted, reports INSERT 0 2, and the row ends up with the values of the last duplicate.

Expected: the same error as PostgreSQL raises, regardless of whether the target row is compressed.

TimescaleDB version affected

2.31.0-dev, built from main at 8ffe9536a

PostgreSQL version used

17.2

What operating system did you use?

macOS 14 (Darwin 23.3.0) arm64

What installation method did you use?

Source

What platform did you run on?

On prem/Self-hosted

Relevant log output and stack trace

bash
-- uncompressed hypertable and plain table:
ERROR:  ON CONFLICT DO UPDATE command cannot affect row a second time
HINT:  Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
-- compressed chunk:
INSERT 0 2

How can we reproduce the bug?

bash
CREATE TABLE t (ts timestamptz NOT NULL, k int, v int);
SELECT create_hypertable('t', 'ts');
CREATE UNIQUE INDEX ON t (ts, k);
INSERT INTO t VALUES ('2024-01-01', 1, 0);

-- rejected, as on a plain table:
INSERT INTO t VALUES ('2024-01-01', 1, 10), ('2024-01-01', 1, 20)
    ON CONFLICT (ts, k) DO UPDATE SET v = EXCLUDED.v;
-- ERROR 21000

ALTER TABLE t SET (timescaledb.compress, timescaledb.compress_segmentby = 'k');
SELECT compress_chunk(c) FROM show_chunks('t') c;

-- accepted:
INSERT INTO t VALUES ('2024-01-01', 1, 10), ('2024-01-01', 1, 20)
    ON CONFLICT (ts, k) DO UPDATE SET v = EXCLUDED.v;
-- INSERT 0 2
SELECT v FROM t;
-- 20