Skip to content

Commit 9c258bd

Browse files
committed
fix(db): align ON CONFLICT clause with existing functional index
The migration script `V6.8.0.1.sql` failed with a `PSQLException` stating "there is no unique or exclusion constraint matching the ON CONFLICT specification". This occurred because the script used a partial index syntax for the conflict target: `ON CONFLICT (name) WHERE lang IS NULL` However, PostgreSQL's `ON CONFLICT` inference requires the target to syntactically match an existing unique index or constraint. The actual index on the `setting` table is a functional index defined as: `CREATE UNIQUE INDEX unique_settings ON setting (name, (COALESCE(lang, '')))` While `WHERE lang IS NULL` and `COALESCE(lang, '')` logically handle nulls similarly for uniqueness in this context, Postgres does not treat them as interchangeable for arbiter inference. This commit updates the migration script to explicitly target the functional index expression: `ON CONFLICT (name, (coalesce(lang, '')))` References: - PostgreSQL 16 Documentation on INSERT: https://www.postgresql.org/docs/16/sql-insert.html#SQL-ON-CONFLICT
1 parent 664b294 commit 9c258bd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/resources/db/migration/V6.8.0.1.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ DO $$
6767
-- Insert or update the new JSON-based setting
6868
INSERT INTO setting (name, content, lang)
6969
VALUES (':TabularIngestSizeLimit', json_object::TEXT, NULL)
70-
ON CONFLICT (name) WHERE lang IS NULL
70+
ON CONFLICT (name, (coalesce(lang, '')))
7171
DO UPDATE SET content = EXCLUDED.content;
7272

7373
-- Delete all format-specific settings

0 commit comments

Comments
 (0)