Skip to content

Commit 6ee2256

Browse files
fix: add pg_catalog prefix logic for SQL standard functions
- Add logic to prepend pg_catalog prefix to single-element function names - Target SQL standard functions like btrim, trim, ltrim, rtrim - Maintain 228/258 passing tests while working on function prefix issues Co-Authored-By: Dan Lynch <[email protected]>
1 parent 24b614f commit 6ee2256

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

packages/transform/src/transformers/v13-to-v14.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class V13ToV14Transformer {
184184
}
185185
}
186186

187-
// Handle pg_catalog prefix removal for specific functions
187+
// Handle pg_catalog prefix for specific functions
188188
if (funcname.length >= 2) {
189189
const firstElement = funcname[0];
190190
const secondElement = funcname[1];
@@ -202,6 +202,23 @@ export class V13ToV14Transformer {
202202
}
203203
}
204204
}
205+
} else if (funcname.length === 1) {
206+
const singleElement = funcname[0];
207+
if (singleElement && typeof singleElement === 'object' && 'String' in singleElement) {
208+
const functionName = singleElement.String.str || singleElement.String.sval;
209+
const sqlSyntaxFunctions = [
210+
'btrim', 'trim', 'ltrim', 'rtrim',
211+
'position', 'overlay',
212+
'extract', 'timezone'
213+
];
214+
215+
if (sqlSyntaxFunctions.includes(functionName.toLowerCase())) {
216+
funcname = [
217+
{ String: { str: 'pg_catalog' } },
218+
...funcname
219+
];
220+
}
221+
}
205222
}
206223

207224
}
@@ -961,22 +978,6 @@ export class V13ToV14Transformer {
961978
return 'COERCE_EXPLICIT_CALL';
962979
}
963980

964-
// Handle btrim function specifically - depends on pg_catalog prefix
965-
if (funcname.toLowerCase() === 'btrim') {
966-
// Check if the function has pg_catalog prefix by examining the node
967-
if (node && node.funcname && Array.isArray(node.funcname) && node.funcname.length >= 2) {
968-
const firstElement = node.funcname[0];
969-
if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
970-
const prefix = firstElement.String.str || firstElement.String.sval;
971-
if (prefix === 'pg_catalog') {
972-
return 'COERCE_SQL_SYNTAX';
973-
}
974-
}
975-
}
976-
return 'COERCE_EXPLICIT_CALL';
977-
}
978-
979-
980981
const explicitCallFunctions = [
981982
'substr', 'timestamptz', 'timestamp', 'date', 'time', 'timetz',
982983
'interval', 'numeric', 'decimal', 'float4', 'float8', 'int2', 'int4', 'int8',

0 commit comments

Comments
 (0)