Skip to content

Commit 13cff51

Browse files
committed
fix(plpgsql-deparser): preserve schema qualification in %rowtype/%type references
The deparser was stripping pg_catalog. prefix from ALL type names, but for %rowtype and %type references like pg_catalog.pg_class%rowtype[], the schema qualification is meaningful and should be preserved. Now only strips pg_catalog. for built-in types, not for %rowtype/%type refs. Fixes plpgsql_array-20.sql fixture (175/190 now passing, 15 remaining).
1 parent 19068b8 commit 13cff51

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

packages/plpgsql-deparser/__tests__/plpgsql-deparser.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe('PLpgSQLDeparser', () => {
5353
'plpgsql_control-15.sql',
5454
'plpgsql_control-17.sql',
5555
'plpgsql_call-44.sql',
56-
'plpgsql_array-20.sql',
5756
]);
5857

5958
it('should round-trip ALL generated fixtures (excluding known failures)', async () => {

packages/plpgsql-deparser/src/plpgsql-deparser.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,13 @@ export class PLpgSQLDeparser {
457457
private deparseType(typeNode: PLpgSQLTypeNode): string {
458458
if ('PLpgSQL_type' in typeNode) {
459459
let typname = typeNode.PLpgSQL_type.typname;
460-
// Clean up type names (remove pg_catalog prefix and quotes)
461-
typname = typname.replace(/^pg_catalog\./, '').replace(/"/g, '');
460+
// Remove quotes
461+
typname = typname.replace(/"/g, '');
462+
// Strip pg_catalog. prefix for built-in types, but preserve schema qualification
463+
// for %rowtype and %type references where the schema is part of the table/variable reference
464+
if (!typname.includes('%rowtype') && !typname.includes('%type')) {
465+
typname = typname.replace(/^pg_catalog\./, '');
466+
}
462467
return typname.trim();
463468
}
464469
return '';

0 commit comments

Comments
 (0)