Address rabbit

This commit is contained in:
Joshen Lim committed 2026-10-05 18:11:20 +08:00
1 parent 420fdd200f
commit ee3ecaf9cd
2 files changed
+31 -4

No files matched your search

@@ -941,16 +941,16 @@ const SCOPED_PG_GET_TABLEDEF_SQL: SafeSqlFragment = safeSql`
bInheritance := False;
IF v_pgversion < 100000 THEN
-- Issue#11: handle parent schema
SELECT c2.relname parent, c2.relnamespace::regnamespace INTO v_parent, v_parent_schema from pg_class c1, pg_namespace n, pg_inherits i, pg_class c2
WHERE n.nspname = in_schema and n.oid = c1.relnamespace and c1.relname = in_table and c1.oid = i.inhrelid and i.inhparent = c2.oid and c1.relkind = 'r';
SELECT c2.relname parent, n2.nspname INTO v_parent, v_parent_schema from pg_class c1, pg_namespace n, pg_inherits i, pg_class c2, pg_namespace n2
WHERE n.nspname = in_schema and n.oid = c1.relnamespace and c1.relname = in_table and c1.oid = i.inhrelid and i.inhparent = c2.oid and c1.relkind = 'r' and n2.oid = c2.relnamespace;
IF (v_parent IS NOT NULL) THEN
bPartition := True;
bInheritance := True;
END IF;
ELSE
-- Issue#11: handle parent schema
SELECT c2.relname parent, c1.relispartition, pg_get_expr(c1.relpartbound, c1.oid, true), c2.relnamespace::regnamespace INTO v_parent, bRelispartition, v_partbound, v_parent_schema from pg_class c1, pg_namespace n, pg_inherits i, pg_class c2
WHERE n.nspname = in_schema and n.oid = c1.relnamespace and c1.relname = in_table and c1.oid = i.inhrelid and i.inhparent = c2.oid and c1.relkind = 'r';
SELECT c2.relname parent, c1.relispartition, pg_get_expr(c1.relpartbound, c1.oid, true), n2.nspname INTO v_parent, bRelispartition, v_partbound, v_parent_schema from pg_class c1, pg_namespace n, pg_inherits i, pg_class c2, pg_namespace n2
WHERE n.nspname = in_schema and n.oid = c1.relnamespace and c1.relname = in_table and c1.oid = i.inhrelid and i.inhparent = c2.oid and c1.relkind = 'r' and n2.oid = c2.relnamespace;
IF (v_parent IS NOT NULL) THEN
bPartition := True;
IF bRelispartition THEN
@@ -38,3 +38,30 @@ test('getTableDefinitionSql (scoped): escapes double quotes in schema, table, co
await db.cleanup()
}
})
test('getTableDefinitionSql (scoped): quotes the parent schema for an inherited table', async () => {
const db = await createTestDatabase()
try {
await db.executeQuery(`
create schema "par""ent1";
create table "par""ent1"."par""ent_tbl" (id bigint primary key);
create schema "chi""ld1";
create table "chi""ld1"."chi""ld_tbl" () inherits ("par""ent1"."par""ent_tbl");
`)
const [{ id }] = await db.executeQuery<{ id: number }[]>(
`select '"chi""ld1"."chi""ld_tbl"'::regclass::oid::int8 as id;`
)
const sql = getTableDefinitionSql({ id, scoped: true })
const [{ definition }] = await db.executeQuery<{ definition: string }[]>(sql)
expect(definition).toContain('INHERITS ("par""ent1"."par""ent_tbl")')
// the generated DDL must itself be valid, executable SQL
await db.executeQuery(`drop table "chi""ld1"."chi""ld_tbl";`)
await db.executeQuery(definition)
} finally {
await db.cleanup()
}
})