UPDATE metadata semantics incorrect
The Postgres response for an UPDATE reports how many rows matched the WHERE clause, regardless of whether the value changed. This differs from the MySQL semantics (reports rows changed), but is equivalent to setting the CLIENT_FOUND_ROWS client compatibility flag.
This bug is critical due to its interpretation by ORMs, where a 0 result is used as proof of absence from a table.
CREATE TABLE bug3 (id integer PRIMARY KEY, v text);
INSERT INTO bug3 VALUES (1, 'same');
UPDATE bug3 SET v = 'same' WHERE id = 1; -- reports 0; PostgreSQL reports 1
UPDATE bug3 SET v = 'different' WHERE id = 1; -- reports 1
UPDATE bug3 SET v = 'x' WHERE id = 999; -- reports 0
A runnable reproduction of this bug on DoltgreSQL 1.3.1, side by side with PostgreSQL 18.6, is at https://github.com/Reliable-Collaboration/repro-doltgresql-bug-update-row-count.
On DoltgreSQL 1.3.1, the command tag of an UPDATE counts only the rows whose values changed:
UPDATE t SET a = a WHERE id = 1 matches one row and answers UPDATE 0. PostgreSQL 18.6 counts every row
the UPDATE matched, changed or not, and answers UPDATE 1; for an UPDATE that matches two rows and
changes one, PostgreSQL answers UPDATE 2 and DoltgreSQL UPDATE 1.
git clone https://github.com/Reliable-Collaboration/repro-doltgresql-bug-update-row-count.git
cd repro-doltgresql-bug-update-row-count
./repro.sh
The test
CREATE TABLE t (id int PRIMARY KEY, a int);
INSERT INTO t VALUES (1, 10), (2, 20);
-- Matches one row and leaves its value as it is.
UPDATE t SET a = a WHERE id = 1;
-- Matches both rows, but only row 2 gets a new value.
UPDATE t SET a = 10;
SELECT * FROM t ORDER BY id;
Other observations
Each variant was run on DoltgreSQL 1.3.1 and on PostgreSQL 18.6, and PostgreSQL ran every one without an error:
- An
UPDATEthat matches three rows and changes none answersUPDATE 0(PostgreSQL:UPDATE 3), and one that matches three rows and changes two answersUPDATE 2(PostgreSQL:UPDATE 3). AnUPDATEthat matches no row answersUPDATE 0on both. - Setting a column to the literal value it already holds, a text column to the same text, or a NULL to
NULL answers
UPDATE 0(PostgreSQL:UPDATE 1). - So does an
UPDATEthat changes nothing inside an explicit transaction, on a table without a primary key, or on a table with aBEFORE UPDATEtrigger that returnsNEW, and so doesSET id = idon the primary key. - An
UPDATEsent through the extended query protocol with psql's\bind, setting a value the row already holds, answersUPDATE 0(PostgreSQL:UPDATE 1). - With
RETURNING, the count agrees with PostgreSQL:UPDATE t SET a = a WHERE id = 1 RETURNING id, areturns the row and answersUPDATE 1on both. - In PL/pgSQL,
FOUNDfollows the same count: a function that runsUPDATE t SET a = a WHERE id = 1;and thenRETURN FOUND;returnsf(PostgreSQL:t). INSERT ... ON CONFLICT (id) DO UPDATE SET a = EXCLUDED.aon an existing row answersINSERT 0 0when the row keeps its values andINSERT 0 2when it changes; PostgreSQL answersINSERT 0 1both times.- The
UPDATEcount is also described in dolthub/doltgresql#3113.
Environment
- DoltgreSQL 1.3.1, the newest release when this was written: image
dolthub/doltgresql:1.3.1, digestsha256:6c85cb1f35beabf47f094336a420255130b841b1645f36d79ef046276af36851. Its bundledpsqlis 17.11. - PostgreSQL 18.6: image
postgres:18.6-bookworm, digestsha256:1c59e2c3c818eaa0f0628f695b36e7c9e362d6b219b36a54a32df645cbd7e1af. Its bundledpsqlis 18.6. - Reproduced on 2026-09-10 with Docker 29.7.2 on Linux x86_64 (Ubuntu 26.04.1 LTS under WSL 2).