@@ -1871,7 +1871,7 @@ export class Deparser implements DeparserVisitor {
18711871 // Handle ONLY keyword for inheritance control (but not for type definitions, ALTER TYPE, or CREATE FOREIGN TABLE)
18721872 if ( node && ( ! ( 'inh' in node ) || node . inh === undefined ) &&
18731873 ! context . parentNodeTypes . includes ( 'CompositeTypeStmt' ) &&
1874- ! context . parentNodeTypes . includes ( 'AlterTypeStmt' ) &&
1874+ context . objtype !== 'OBJECT_TYPE' &&
18751875 ! context . parentNodeTypes . includes ( 'CreateForeignTableStmt' ) ) {
18761876 output . push ( 'ONLY' ) ;
18771877 }
@@ -4644,9 +4644,7 @@ export class Deparser implements DeparserVisitor {
46444644 output . push ( 'IF EXISTS' ) ;
46454645 }
46464646
4647- const alterContext = node . objtype === 'OBJECT_TYPE'
4648- ? context . spawn ( 'AlterTypeStmt' )
4649- : context ;
4647+ const alterContext = context . spawn ( 'AlterTableStmt' , { objtype : node . objtype } ) ;
46504648
46514649 if ( node . relation ) {
46524650 const relationStr = this . RangeVar ( node . relation , alterContext ) ;
@@ -4683,7 +4681,7 @@ export class Deparser implements DeparserVisitor {
46834681 if ( node . subtype ) {
46844682 switch ( node . subtype ) {
46854683 case 'AT_AddColumn' :
4686- if ( context . parentNodeTypes . includes ( 'AlterTypeStmt' ) ) {
4684+ if ( context . objtype === 'OBJECT_TYPE' ) {
46874685 output . push ( 'ADD ATTRIBUTE' ) ;
46884686 } else {
46894687 output . push ( 'ADD COLUMN' ) ;
@@ -4736,13 +4734,13 @@ export class Deparser implements DeparserVisitor {
47364734 break ;
47374735 case 'AT_DropColumn' :
47384736 if ( node . missing_ok ) {
4739- if ( context . parentNodeTypes . includes ( 'AlterTypeStmt' ) ) {
4737+ if ( context . objtype === 'OBJECT_TYPE' ) {
47404738 output . push ( 'DROP ATTRIBUTE IF EXISTS' ) ;
47414739 } else {
47424740 output . push ( 'DROP COLUMN IF EXISTS' ) ;
47434741 }
47444742 } else {
4745- if ( context . parentNodeTypes . includes ( 'AlterTypeStmt' ) ) {
4743+ if ( context . objtype === 'OBJECT_TYPE' ) {
47464744 output . push ( 'DROP ATTRIBUTE' ) ;
47474745 } else {
47484746 output . push ( 'DROP COLUMN' ) ;
@@ -4758,7 +4756,7 @@ export class Deparser implements DeparserVisitor {
47584756 }
47594757 break ;
47604758 case 'AT_AlterColumnType' :
4761- if ( context . parentNodeTypes . includes ( 'AlterTypeStmt' ) ) {
4759+ if ( context . objtype === 'OBJECT_TYPE' ) {
47624760 output . push ( 'ALTER ATTRIBUTE' ) ;
47634761 } else {
47644762 output . push ( 'ALTER COLUMN' ) ;
@@ -8032,7 +8030,7 @@ export class Deparser implements DeparserVisitor {
80328030 output . push ( this . RangeVar ( node . relation , context ) ) ;
80338031 } else if ( node . relation ) {
80348032 const rangeVarContext = node . relationType === 'OBJECT_TYPE'
8035- ? context . spawn ( 'AlterTypeStmt' )
8033+ ? context . spawn ( 'AlterTypeStmt' , { objtype : 'OBJECT_TYPE' } )
80368034 : context ;
80378035
80388036 // Add ON keyword for policy operations
0 commit comments