From ccfc3cf92c0155584dbd52313225890668c582f7 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Sat, 23 May 2026 09:25:53 +0800 Subject: [PATCH] fix(postgres): remove trailing comma in SQL query for table comments --- crates/dbx-core/src/db/postgres.rs | 2 +- packages/app-tests/postgresSchemaSqlSource.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 packages/app-tests/postgresSchemaSqlSource.test.ts diff --git a/crates/dbx-core/src/db/postgres.rs b/crates/dbx-core/src/db/postgres.rs index 7061942b03..957296dc77 100644 --- a/crates/dbx-core/src/db/postgres.rs +++ b/crates/dbx-core/src/db/postgres.rs @@ -220,7 +220,7 @@ fn postgres_tables_sql() -> &'static str { CASE c.relkind WHEN 'r' THEN 'BASE TABLE' WHEN 'v' THEN 'VIEW' \ WHEN 'm' THEN 'MATERIALIZED VIEW' WHEN 'f' THEN 'FOREIGN TABLE' \ WHEN 'p' THEN 'BASE TABLE' END AS table_type, \ - obj_description(c.oid) AS table_comment, \ + obj_description(c.oid) AS table_comment \ FROM pg_catalog.pg_class c \ JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \ WHERE n.nspname = $1 AND c.relkind IN ('r','v','m','f','p') \ diff --git a/packages/app-tests/postgresSchemaSqlSource.test.ts b/packages/app-tests/postgresSchemaSqlSource.test.ts new file mode 100644 index 0000000000..610df2ac24 --- /dev/null +++ b/packages/app-tests/postgresSchemaSqlSource.test.ts @@ -0,0 +1,10 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; + +const source = readFileSync("crates/dbx-core/src/db/postgres.rs", "utf8"); + +test("postgres table list SQL has no trailing comma before FROM", () => { + assert.doesNotMatch(source, /AS table_comment,\s*\\\s*FROM pg_catalog\.pg_class/); + assert.match(source, /obj_description\(c\.oid\) AS table_comment\s*\\\s*FROM pg_catalog\.pg_class/); +});