From 1910eecf54bb1028a3393fad45a40038f47a386b Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 22 Jul 2026 22:16:57 +0300 Subject: [PATCH] fix(numbering): quote the counter column in the increment SET expression (PostgreSQL) DocumentNumberStore creates DIRIGIBLE_DOCUMENT_NUMBERS with quoted (case-sensitive, upper-case) identifiers, and the SQL builder encapsulates the SET-target column and the WHERE-condition identifiers the same way. But the increment's SET VALUE is a free expression appended verbatim - `SET "DOCUMENT_COUNTER" = DOCUMENT_COUNTER + 1` - whose column reference was NOT quoted. On a case-folding dialect (PostgreSQL lower-cases unquoted identifiers) it resolved to `document_counter`, which does not match the quoted-upper-case column: `ERROR: column "document_counter" does not exist`. H2 upper-cases unquoted identifiers, so it happened to match there - which is why the h2 integration job was green while integration-tests-postgresql failed in NumberingSdkIT.allocatesAGapFreeFormattedSequence. Fix: quote the column reference in the SET value expression (QUOTED_COUNTER). The WHERE columns stay unquoted on purpose - the builder encapsulates those, and quoting them here double-encapsulates into a zero-length delimited identifier. Verified: NumberingSdkIT run against a real postgres:16 (the CI datasource env) is green after the fix (was: column-does-not-exist). Co-Authored-By: Claude Opus 4.8 --- .../components/engine/numbering/DocumentNumberStore.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/engine/engine-numbering/src/main/java/org/eclipse/dirigible/components/engine/numbering/DocumentNumberStore.java b/components/engine/engine-numbering/src/main/java/org/eclipse/dirigible/components/engine/numbering/DocumentNumberStore.java index be66527482..6112c53668 100644 --- a/components/engine/engine-numbering/src/main/java/org/eclipse/dirigible/components/engine/numbering/DocumentNumberStore.java +++ b/components/engine/engine-numbering/src/main/java/org/eclipse/dirigible/components/engine/numbering/DocumentNumberStore.java @@ -146,10 +146,17 @@ void setCounter(String series, String scope, long value) throws SQLException { } private int increment(Connection connection, String series, String scope) throws SQLException { + // The table is created with QUOTED (case-sensitive) identifiers, and the builder encapsulates + // the SET-target column and the WHERE-condition identifiers the same way. But the SET VALUE is a + // free expression appended verbatim (NOT encapsulated) - so its column reference must be quoted + // explicitly, otherwise a case-folding dialect (PostgreSQL lower-cases unquoted identifiers) + // fails to resolve it against the quoted-uppercase column (H2 upper-cases unquoted, so it + // happened to match). The WHERE columns stay unquoted: the builder quotes those for us (quoting + // them here would double-encapsulate into a zero-length delimited identifier). String sql = SqlFactory.getNative(connection) .update() .table(TABLE_NAME) - .set(COLUMN_COUNTER, COLUMN_COUNTER + " + 1") + .set(COLUMN_COUNTER, QUOTED_COUNTER + " + 1") .where(COLUMN_SERIES + " = ? AND " + COLUMN_SCOPE + " = ?") .build(); try (PreparedStatement statement = connection.prepareStatement(sql)) {