Skip to content

Commit d932a99

Browse files
Extend :: syntax to function calls for pg_catalog types
- Allow FuncCall node types to use :: syntax when casting to pg_catalog types - Successfully converts CAST(public.gen_random_uuid() AS text) to public.gen_random_uuid()::text - Updated pg-catalog test snapshot to reflect new behavior - All 267 test suites pass with no regressions Co-Authored-By: Dan Lynch <[email protected]>
1 parent bba1147 commit d932a99

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/deparser/__tests__/misc/__snapshots__/pg-catalog.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`should format pg_catalog.char with pretty option enabled 1`] = `
44
"CREATE TABLE dashboard_jobs.jobs (
55
id bigserial PRIMARY KEY,
6-
queue_name text DEFAULT CAST(public.gen_random_uuid() AS text),
6+
queue_name text DEFAULT public.gen_random_uuid()::text,
77
task_identifier text NOT NULL,
88
payload pg_catalog.json DEFAULT '{}'::json NOT NULL,
99
priority int DEFAULT 0 NOT NULL,

packages/deparser/src/deparser.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,11 +2124,13 @@ export class Deparser implements DeparserVisitor {
21242124
if (this.isPgCatalogType(typeName)) {
21252125
const argType = this.getNodeType(node.arg);
21262126

2127-
// Avoid :: syntax for expressions that might need parentheses or complex structures
21282127
const isSimpleArgument = argType === 'A_Const' || argType === 'ColumnRef';
2128+
const isFunctionCall = argType === 'FuncCall';
21292129

2130-
if (isSimpleArgument) {
2131-
if (!arg.includes('(') && !arg.startsWith('-')) {
2130+
if (isSimpleArgument || isFunctionCall) {
2131+
// For simple arguments, avoid :: syntax if they have complex structure
2132+
if (isSimpleArgument && (arg.includes('(') || arg.startsWith('-'))) {
2133+
} else {
21322134
const cleanTypeName = typeName.replace('pg_catalog.', '');
21332135
return `${arg}::${cleanTypeName}`;
21342136
}

0 commit comments

Comments
 (0)