Skip to content

Commit 9c7e1f8

Browse files
Fix ALTER EXTENSION deparsing issues
- Fix ALTER EXTENSION UPDATE TO deparsing: change defname check from 'to' to 'new_version' and output 'UPDATE TO' instead of just 'TO' - Fix ALTER EXTENSION SET SCHEMA deparsing: output 'SET SCHEMA' instead of just 'SCHEMA' - Add AlterExtensionContentsStmt handler for ALTER EXTENSION ADD/DROP statements - All tests pass (285 test suites, 655 tests) Co-Authored-By: Dan Lynch <[email protected]>
1 parent 8315d28 commit 9c7e1f8

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

packages/deparser/src/deparser.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6101,11 +6101,15 @@ export class Deparser implements DeparserVisitor {
61016101
if (context.parentNodeTypes.includes('CreateExtensionStmt') || context.parentNodeTypes.includes('AlterExtensionStmt') || context.parentNodeTypes.includes('CreateFdwStmt') || context.parentNodeTypes.includes('AlterFdwStmt')) {
61026102
// AlterExtensionStmt specific cases
61036103
if (context.parentNodeTypes.includes('AlterExtensionStmt')) {
6104-
if (node.defname === 'to') {
6105-
return `TO ${argValue}`;
6104+
if (node.defname === 'new_version') {
6105+
// argValue is unquoted due to DefElem context, so we need to quote it
6106+
const quotedValue = typeof argValue === 'string' && !argValue.startsWith("'")
6107+
? `'${argValue}'`
6108+
: argValue;
6109+
return `UPDATE TO ${quotedValue}`;
61066110
}
61076111
if (node.defname === 'schema') {
6108-
return `SCHEMA ${argValue}`;
6112+
return `SET SCHEMA ${argValue}`;
61096113
}
61106114
}
61116115

@@ -6415,6 +6419,38 @@ export class Deparser implements DeparserVisitor {
64156419
return output.join(' ');
64166420
}
64176421

6422+
AlterExtensionContentsStmt(node: t.AlterExtensionContentsStmt, context: DeparserContext): string {
6423+
const output: string[] = ['ALTER', 'EXTENSION'];
6424+
6425+
if (node.extname) {
6426+
output.push(this.quoteIfNeeded(node.extname));
6427+
}
6428+
6429+
// Handle action: 1 = ADD, -1 = DROP
6430+
if (node.action === 1) {
6431+
output.push('ADD');
6432+
} else if (node.action === -1) {
6433+
output.push('DROP');
6434+
}
6435+
6436+
// Add object type keyword
6437+
if (node.objtype) {
6438+
try {
6439+
output.push(this.getObjectTypeKeyword(node.objtype));
6440+
} catch {
6441+
// Fallback to the raw objtype if not supported
6442+
output.push(node.objtype.toString());
6443+
}
6444+
}
6445+
6446+
// Add the object itself
6447+
if (node.object) {
6448+
output.push(this.visit(node.object, context));
6449+
}
6450+
6451+
return output.join(' ');
6452+
}
6453+
64186454
CreateFdwStmt(node: t.CreateFdwStmt, context: DeparserContext): string {
64196455
const output: string[] = ['CREATE', 'FOREIGN', 'DATA', 'WRAPPER'];
64206456

0 commit comments

Comments
 (0)