Skip to content

Commit 7294a06

Browse files
committed
fix: exclude all TypeCast contexts from JSON pg_catalog prefix logic
Co-Authored-By: Dan Lynch <[email protected]>
1 parent 4ad9fbb commit 7294a06

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

packages/transform/src/transformers/v16-to-v17.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,31 +441,22 @@ export class V16ToV17Transformer {
441441
}
442442

443443
TypeName(node: PG16.TypeName, context: TransformerContext): any {
444-
console.log('TypeName DEBUG - Called with node:', JSON.stringify(node, null, 2));
445444
const result: any = {};
446445

447446
if (node.names !== undefined) {
448-
console.log('TypeName DEBUG - Original node.names:', JSON.stringify(node.names, null, 2));
449-
450447
let names = Array.isArray(node.names)
451448
? node.names.map(item => this.transform(item as any, context))
452449
: this.transform(node.names as any, context);
453450

454-
console.log('TypeName DEBUG - After transformation, names:', JSON.stringify(names, null, 2));
455-
456451
if (Array.isArray(names) && names.length === 1) {
457452
const singleElement = names[0];
458-
console.log('TypeName DEBUG - Single element:', JSON.stringify(singleElement, null, 2));
459453
if (singleElement && typeof singleElement === 'object' && 'String' in singleElement) {
460454
const typeName = singleElement.String.str || singleElement.String.sval;
461-
console.log('TypeName DEBUG - Found single element type:', typeName);
462-
if (typeName === 'json') {
463-
console.log('TypeName DEBUG - Adding pg_catalog prefix for JSON type');
455+
if (typeName === 'json' && !this.isInValuesContext(context) && !this.isInTypeCastContext(context)) {
464456
names = [
465457
{ String: { sval: 'pg_catalog' } },
466458
...names
467459
];
468-
console.log('TypeName DEBUG - After adding prefix, names:', JSON.stringify(names, null, 2));
469460
}
470461
}
471462
}
@@ -1609,8 +1600,7 @@ export class V16ToV17Transformer {
16091600
'position', 'overlay', 'substring',
16101601
'extract', 'timezone', 'xmlexists',
16111602
'current_date', 'current_time', 'current_timestamp',
1612-
'localtime', 'localtimestamp', 'overlaps',
1613-
'collation_for'
1603+
'localtime', 'localtimestamp', 'overlaps'
16141604
];
16151605

16161606
// Handle specific functions that depend on pg_catalog prefix
@@ -1635,6 +1625,13 @@ export class V16ToV17Transformer {
16351625
return 'COERCE_EXPLICIT_CALL';
16361626
}
16371627

1628+
if (functionName.toLowerCase() === 'pg_collation_for') {
1629+
if (hasPgCatalogPrefix) {
1630+
return 'COERCE_SQL_SYNTAX';
1631+
}
1632+
return 'COERCE_EXPLICIT_CALL';
1633+
}
1634+
16381635
if (sqlSyntaxFunctions.includes(functionName.toLowerCase())) {
16391636
return 'COERCE_SQL_SYNTAX';
16401637
}

0 commit comments

Comments
 (0)