@@ -197,15 +197,17 @@ export class V13ToV14Transformer {
197197 if ( prefix === 'pg_catalog' ) {
198198 const isInCreateDomainContext = this . isInCreateDomainContext ( context ) ;
199199 const isInCallStmtContext = this . isInCallStmtContext ( context ) ;
200+ const isInSelectTargetContext = this . isInSelectTargetContext ( context ) ;
200201
201202 if ( isInCreateDomainContext ) {
202203 funcname = funcname . slice ( 1 ) ;
204+ } else if ( ( isInSelectTargetContext || this . isInReturningContext ( context ) ) && functionName === 'substring' ) {
205+ const hasThreeArgs = node . args && Array . isArray ( node . args ) && node . args . length === 3 ;
206+ if ( hasThreeArgs ) {
207+ funcname = funcname . slice ( 1 ) ;
208+ }
203209 }
204210
205- // Remove pg_catalog prefix from substring functions in CallStmt contexts
206- if ( isInCallStmtContext && functionName === 'substring' ) {
207- funcname = funcname . slice ( 1 ) ;
208- }
209211 }
210212 }
211213 } else if ( funcname . length === 1 ) {
@@ -452,6 +454,19 @@ export class V13ToV14Transformer {
452454 return false ;
453455 } ) ;
454456 }
457+
458+ private isInSelectTargetContext ( context : TransformerContext ) : boolean {
459+ const parentNodeTypes = context . parentNodeTypes || [ ] ;
460+ // Check if we're in a SelectStmt and ResTarget context (which indicates targetList)
461+ return parentNodeTypes . includes ( 'SelectStmt' ) && parentNodeTypes . includes ( 'ResTarget' ) ;
462+ }
463+
464+ private isInReturningContext ( context : TransformerContext ) : boolean {
465+ const parentNodeTypes = context . parentNodeTypes || [ ] ;
466+ // Check if we're in a ResTarget context within UPDATE or DELETE RETURNING clauses
467+ return parentNodeTypes . includes ( 'ResTarget' ) &&
468+ ( parentNodeTypes . includes ( 'UpdateStmt' ) || parentNodeTypes . includes ( 'DeleteStmt' ) ) ;
469+ }
455470 private isInCreateIndexContext ( context : TransformerContext ) : boolean {
456471 const path = context . path || [ ] ;
457472 return path . some ( ( node : any ) =>
@@ -800,7 +815,7 @@ export class V13ToV14Transformer {
800815 if ( result . name . objargs && ! result . name . objfuncargs ) {
801816 // Check if this is an operator by looking at the objname
802817 const isOperator = this . isOperatorName ( result . name . objname ) ;
803-
818+
804819 if ( ! isOperator ) {
805820 result . name . objfuncargs = Array . isArray ( result . name . objargs )
806821 ? result . name . objargs . map ( ( arg : any , index : number ) => this . createFunctionParameterFromTypeName ( arg , context , index ) )
@@ -1113,7 +1128,6 @@ export class V13ToV14Transformer {
11131128 FunctionParameter ( node : PG13 . FunctionParameter , context : TransformerContext ) : { FunctionParameter : PG14 . FunctionParameter } {
11141129 const result : any = { } ;
11151130
1116-
11171131 if ( node . name !== undefined ) {
11181132 result . name = node . name ;
11191133 }
@@ -2277,10 +2291,7 @@ export class V13ToV14Transformer {
22772291 ! context . parentNodeTypes . includes ( 'CreateTransformStmt' ) &&
22782292 ! context . parentNodeTypes . includes ( 'DropStmt' ) ;
22792293
2280- const isInDropStmtContext = context && context . parentNodeTypes &&
2281- context . parentNodeTypes . includes ( 'DropStmt' ) ;
2282-
2283- if ( typeNameNode && typeNameNode . name && shouldAddParameterName && ! isInDropStmtContext ) {
2294+ if ( typeNameNode && typeNameNode . name && shouldAddParameterName ) {
22842295 functionParam . name = typeNameNode . name ;
22852296 }
22862297
@@ -2307,6 +2318,7 @@ export class V13ToV14Transformer {
23072318 return false ;
23082319 }
23092320
2321+
23102322 private transformA_Expr_Kind ( kind : string ) : string {
23112323 const pg13ToP14Map : { [ key : string ] : string } = {
23122324 'AEXPR_OP' : 'AEXPR_OP' ,
@@ -3180,4 +3192,38 @@ export class V13ToV14Transformer {
31803192 return pg13Mode ;
31813193 }
31823194 }
3195+
3196+ ReindexStmt ( node : PG13 . ReindexStmt , context : TransformerContext ) : { ReindexStmt : PG14 . ReindexStmt } {
3197+ const result : any = { } ;
3198+
3199+ if ( node . kind !== undefined ) {
3200+ result . kind = node . kind ;
3201+ }
3202+
3203+ if ( node . relation !== undefined ) {
3204+ result . relation = this . transform ( node . relation as any , context ) ;
3205+ }
3206+
3207+ if ( node . name !== undefined ) {
3208+ result . name = node . name ;
3209+ }
3210+
3211+ const nodeAny = node as any ;
3212+ if ( nodeAny . options !== undefined ) {
3213+ const params = [ ] ;
3214+ if ( nodeAny . options & 1 ) { // REINDEXOPT_VERBOSE
3215+ params . push ( {
3216+ DefElem : {
3217+ defname : 'verbose' ,
3218+ defaction : 'DEFELEM_UNSPEC'
3219+ }
3220+ } ) ;
3221+ }
3222+ result . params = params ;
3223+ } else if ( nodeAny . params !== undefined ) {
3224+ result . params = this . transform ( nodeAny . params , context ) ;
3225+ }
3226+
3227+ return { ReindexStmt : result } ;
3228+ }
31833229}
0 commit comments