From 7e90320afa3c62067fb3a35c9f34373719bf2fa3 Mon Sep 17 00:00:00 2001 From: Henry Su Date: Fri, 4 Sep 2026 10:46:53 -0500 Subject: [PATCH] fix: quote check constraint names when dropping via column update Hyphenated or otherwise non-plain check names need %I; %s produced invalid DROP CONSTRAINT SQL on PATCH /columns when clearing checks. --- src/lib/PostgresMetaColumns.ts | 2 +- test/lib/columns.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/lib/PostgresMetaColumns.ts b/src/lib/PostgresMetaColumns.ts index 613c8ea2a..e94cbbc11 100644 --- a/src/lib/PostgresMetaColumns.ts +++ b/src/lib/PostgresMetaColumns.ts @@ -332,7 +332,7 @@ BEGIN IF v_conname IS NOT NULL THEN EXECUTE format('ALTER TABLE ${ident(old!.schema)}.${ident( old!.table - )} DROP CONSTRAINT %s', v_conname); + )} DROP CONSTRAINT %I', v_conname); END IF; ${ diff --git a/test/lib/columns.ts b/test/lib/columns.ts index 3fcac79fe..4137ca8f7 100644 --- a/test/lib/columns.ts +++ b/test/lib/columns.ts @@ -981,6 +981,27 @@ test('dropping column checks', async () => { await pgMeta.query(`drop table t`) }) +test('dropping hyphenated column check constraints', async () => { + await pgMeta.query(` + create table public.t (c int8); + alter table public.t add constraint "t-c-check" check (c <> 0); + `) + + let res = await pgMeta.columns.retrieve({ + schema: 'public', + table: 't', + name: 'c', + }) + expect(res.error).toBeNull() + expect(res.data?.check).toBeTruthy() + + res = await pgMeta.columns.update(res.data!.id, { check: null }) + expect(res.error).toBeNull() + expect(res.data?.check).toBeNull() + + await pgMeta.query(`drop table public.t`) +}) + test('column with fully-qualified type', async () => { await pgMeta.query(`create table public.t(); create schema s; create type s.my_type as enum ();`)