@pgsql/transform 18.1.1 → 18.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +24 -76
  2. package/esm/facts.js +289 -0
  3. package/esm/index.js +5 -22
  4. package/esm/qualify.js +297 -0
  5. package/esm/round-trip-core.js +126 -0
  6. package/esm/round-trip.js +116 -0
  7. package/esm/transform.js +1169 -0
  8. package/facts.d.ts +69 -0
  9. package/facts.js +292 -0
  10. package/index.d.ts +10 -28
  11. package/index.js +37 -76
  12. package/package.json +22 -14
  13. package/qualify.d.ts +125 -0
  14. package/qualify.js +303 -0
  15. package/round-trip-core.d.ts +60 -0
  16. package/round-trip-core.js +133 -0
  17. package/round-trip.d.ts +47 -0
  18. package/round-trip.js +123 -0
  19. package/transform.d.ts +259 -0
  20. package/transform.js +1190 -0
  21. package/13/enums.d.ts +0 -62
  22. package/13/enums.js +0 -2
  23. package/13/types.d.ts +0 -2103
  24. package/13/types.js +0 -2
  25. package/14/enums.d.ts +0 -62
  26. package/14/enums.js +0 -2
  27. package/14/types.d.ts +0 -2164
  28. package/14/types.js +0 -2
  29. package/15/enums.d.ts +0 -64
  30. package/15/enums.js +0 -2
  31. package/15/types.d.ts +0 -2222
  32. package/15/types.js +0 -2
  33. package/16/enums.d.ts +0 -69
  34. package/16/enums.js +0 -2
  35. package/16/types.d.ts +0 -2328
  36. package/16/types.js +0 -2
  37. package/17/enums.d.ts +0 -76
  38. package/17/enums.js +0 -2
  39. package/17/types.d.ts +0 -2488
  40. package/17/types.js +0 -2
  41. package/18/enums.d.ts +0 -78
  42. package/18/enums.js +0 -2
  43. package/18/types.d.ts +0 -2538
  44. package/18/types.js +0 -2
  45. package/esm/13/enums.js +0 -1
  46. package/esm/13/types.js +0 -1
  47. package/esm/14/enums.js +0 -1
  48. package/esm/14/types.js +0 -1
  49. package/esm/15/enums.js +0 -1
  50. package/esm/15/types.js +0 -1
  51. package/esm/16/enums.js +0 -1
  52. package/esm/16/types.js +0 -1
  53. package/esm/17/enums.js +0 -1
  54. package/esm/17/types.js +0 -1
  55. package/esm/18/enums.js +0 -1
  56. package/esm/18/types.js +0 -1
  57. package/esm/multi-version-transformer.js +0 -80
  58. package/esm/transformers/context.js +0 -1
  59. package/esm/transformers/v13-to-v14.js +0 -2767
  60. package/esm/transformers/v14-to-v15.js +0 -1218
  61. package/esm/transformers/v15-to-v16.js +0 -2935
  62. package/esm/transformers/v16-to-v17.js +0 -1526
  63. package/esm/transformers/v17-to-v18.js +0 -204
  64. package/esm/transformers-direct/index.js +0 -13
  65. package/esm/transformers-direct/v13-to-v17/index.js +0 -74
  66. package/esm/transformers-direct/v13-to-v18/index.js +0 -84
  67. package/esm/transformers-direct/v14-to-v17/index.js +0 -63
  68. package/esm/transformers-direct/v14-to-v18/index.js +0 -73
  69. package/esm/transformers-direct/v15-to-v17/index.js +0 -53
  70. package/esm/transformers-direct/v15-to-v18/index.js +0 -62
  71. package/esm/transformers-direct/v16-to-v17/index.js +0 -40
  72. package/esm/transformers-direct/v16-to-v18/index.js +0 -51
  73. package/esm/transformers-direct/v17-to-v18/index.js +0 -39
  74. package/multi-version-transformer.d.ts +0 -14
  75. package/multi-version-transformer.js +0 -84
  76. package/transformers/context.d.ts +0 -4
  77. package/transformers/context.js +0 -2
  78. package/transformers/v13-to-v14.d.ts +0 -255
  79. package/transformers/v13-to-v14.js +0 -2771
  80. package/transformers/v14-to-v15.d.ts +0 -615
  81. package/transformers/v14-to-v15.js +0 -1222
  82. package/transformers/v15-to-v16.d.ts +0 -632
  83. package/transformers/v15-to-v16.js +0 -2939
  84. package/transformers/v16-to-v17.d.ts +0 -640
  85. package/transformers/v16-to-v17.js +0 -1530
  86. package/transformers/v17-to-v18.d.ts +0 -54
  87. package/transformers/v17-to-v18.js +0 -208
  88. package/transformers-direct/index.d.ts +0 -13
  89. package/transformers-direct/index.js +0 -25
  90. package/transformers-direct/v13-to-v17/index.d.ts +0 -27
  91. package/transformers-direct/v13-to-v17/index.js +0 -78
  92. package/transformers-direct/v13-to-v18/index.d.ts +0 -28
  93. package/transformers-direct/v13-to-v18/index.js +0 -88
  94. package/transformers-direct/v14-to-v17/index.d.ts +0 -26
  95. package/transformers-direct/v14-to-v17/index.js +0 -67
  96. package/transformers-direct/v14-to-v18/index.d.ts +0 -27
  97. package/transformers-direct/v14-to-v18/index.js +0 -77
  98. package/transformers-direct/v15-to-v17/index.d.ts +0 -25
  99. package/transformers-direct/v15-to-v17/index.js +0 -57
  100. package/transformers-direct/v15-to-v18/index.d.ts +0 -26
  101. package/transformers-direct/v15-to-v18/index.js +0 -66
  102. package/transformers-direct/v16-to-v17/index.d.ts +0 -24
  103. package/transformers-direct/v16-to-v17/index.js +0 -44
  104. package/transformers-direct/v16-to-v18/index.d.ts +0 -25
  105. package/transformers-direct/v16-to-v18/index.js +0 -55
  106. package/transformers-direct/v17-to-v18/index.d.ts +0 -24
  107. package/transformers-direct/v17-to-v18/index.js +0 -43
@@ -1,1526 +0,0 @@
1
- /**
2
- * V16 to V17 AST Transformer
3
- * Transforms PostgreSQL v16 AST nodes to v17 format
4
- */
5
- export class V16ToV17Transformer {
6
- transform(node, context = { parentNodeTypes: [] }) {
7
- if (node == null) {
8
- return null;
9
- }
10
- if (typeof node === 'number' || node instanceof Number) {
11
- return node;
12
- }
13
- if (typeof node === 'string') {
14
- return node;
15
- }
16
- try {
17
- return this.visit(node, context);
18
- }
19
- catch (error) {
20
- const nodeType = Object.keys(node)[0];
21
- throw new Error(`Error transforming ${nodeType}: ${error.message}`);
22
- }
23
- }
24
- visit(node, context = { parentNodeTypes: [] }) {
25
- const nodeType = this.getNodeType(node);
26
- // Handle empty objects
27
- if (!nodeType) {
28
- return {};
29
- }
30
- const nodeData = this.getNodeData(node);
31
- const methodName = nodeType;
32
- if (typeof this[methodName] === 'function') {
33
- const childContext = {
34
- ...context,
35
- parentNodeTypes: [...context.parentNodeTypes, nodeType]
36
- };
37
- const result = this[methodName](nodeData, childContext);
38
- return result;
39
- }
40
- // If no specific method, return the node as-is
41
- return node;
42
- }
43
- getNodeType(node) {
44
- return Object.keys(node)[0];
45
- }
46
- getNodeData(node) {
47
- const keys = Object.keys(node);
48
- if (keys.length === 1 && typeof node[keys[0]] === 'object') {
49
- return node[keys[0]];
50
- }
51
- return node;
52
- }
53
- ParseResult(node, context) {
54
- if (node && typeof node === 'object' && 'version' in node && 'stmts' in node) {
55
- return {
56
- version: 170004, // PG17 version
57
- stmts: node.stmts.map((stmt) => {
58
- if (stmt && typeof stmt === 'object' && 'stmt' in stmt) {
59
- return {
60
- ...stmt,
61
- stmt: this.transform(stmt.stmt, context)
62
- };
63
- }
64
- return this.transform(stmt, context);
65
- })
66
- };
67
- }
68
- return node;
69
- }
70
- RawStmt(node, context) {
71
- const result = {};
72
- if (node.stmt !== undefined) {
73
- result.stmt = this.transform(node.stmt, context);
74
- }
75
- if (node.stmt_location !== undefined) {
76
- result.stmt_location = node.stmt_location;
77
- }
78
- if (node.stmt_len !== undefined) {
79
- result.stmt_len = node.stmt_len;
80
- }
81
- return { RawStmt: result };
82
- }
83
- SelectStmt(node, context) {
84
- const result = {};
85
- if (node.distinctClause !== undefined) {
86
- result.distinctClause = Array.isArray(node.distinctClause)
87
- ? node.distinctClause.map(item => this.transform(item, context))
88
- : this.transform(node.distinctClause, context);
89
- }
90
- if (node.intoClause !== undefined) {
91
- result.intoClause = this.transform(node.intoClause, context);
92
- }
93
- if (node.targetList !== undefined) {
94
- result.targetList = Array.isArray(node.targetList)
95
- ? node.targetList.map(item => this.transform(item, context))
96
- : this.transform(node.targetList, context);
97
- }
98
- if (node.fromClause !== undefined) {
99
- result.fromClause = Array.isArray(node.fromClause)
100
- ? node.fromClause.map(item => this.transform(item, context))
101
- : this.transform(node.fromClause, context);
102
- }
103
- if (node.whereClause !== undefined) {
104
- result.whereClause = this.transform(node.whereClause, context);
105
- }
106
- if (node.groupClause !== undefined) {
107
- result.groupClause = Array.isArray(node.groupClause)
108
- ? node.groupClause.map(item => this.transform(item, context))
109
- : this.transform(node.groupClause, context);
110
- }
111
- if (node.groupDistinct !== undefined) {
112
- result.groupDistinct = node.groupDistinct;
113
- }
114
- if (node.havingClause !== undefined) {
115
- result.havingClause = this.transform(node.havingClause, context);
116
- }
117
- if (node.windowClause !== undefined) {
118
- result.windowClause = Array.isArray(node.windowClause)
119
- ? node.windowClause.map(item => this.transform(item, context))
120
- : this.transform(node.windowClause, context);
121
- }
122
- if (node.valuesLists !== undefined) {
123
- const valuesContext = {
124
- ...context,
125
- inValuesClause: true
126
- };
127
- result.valuesLists = Array.isArray(node.valuesLists)
128
- ? node.valuesLists.map(item => Array.isArray(item)
129
- ? item.map(subItem => this.transform(subItem, valuesContext))
130
- : this.transform(item, valuesContext))
131
- : this.transform(node.valuesLists, valuesContext);
132
- }
133
- if (node.sortClause !== undefined) {
134
- result.sortClause = Array.isArray(node.sortClause)
135
- ? node.sortClause.map(item => this.transform(item, context))
136
- : this.transform(node.sortClause, context);
137
- }
138
- if (node.limitOffset !== undefined) {
139
- result.limitOffset = this.transform(node.limitOffset, context);
140
- }
141
- if (node.limitCount !== undefined) {
142
- result.limitCount = this.transform(node.limitCount, context);
143
- }
144
- if (node.limitOption !== undefined) {
145
- result.limitOption = node.limitOption;
146
- }
147
- if (node.lockingClause !== undefined) {
148
- result.lockingClause = Array.isArray(node.lockingClause)
149
- ? node.lockingClause.map(item => this.transform(item, context))
150
- : this.transform(node.lockingClause, context);
151
- }
152
- if (node.withClause !== undefined) {
153
- result.withClause = this.transform(node.withClause, context);
154
- }
155
- if (node.op !== undefined) {
156
- result.op = node.op;
157
- }
158
- if (node.all !== undefined) {
159
- result.all = node.all;
160
- }
161
- if (node.larg !== undefined) {
162
- result.larg = this.transform(node.larg, context);
163
- }
164
- if (node.rarg !== undefined) {
165
- result.rarg = this.transform(node.rarg, context);
166
- }
167
- return { SelectStmt: result };
168
- }
169
- A_Expr(node, context) {
170
- const result = {};
171
- if (node.kind !== undefined) {
172
- result.kind = node.kind;
173
- }
174
- if (node.name !== undefined) {
175
- result.name = Array.isArray(node.name)
176
- ? node.name.map(item => this.transform(item, context))
177
- : this.transform(node.name, context);
178
- }
179
- if (node.lexpr !== undefined) {
180
- result.lexpr = this.transform(node.lexpr, context);
181
- }
182
- if (node.rexpr !== undefined) {
183
- result.rexpr = this.transform(node.rexpr, context);
184
- }
185
- if (node.location !== undefined) {
186
- result.location = node.location;
187
- }
188
- return { A_Expr: result };
189
- }
190
- InsertStmt(node, context) {
191
- const result = {};
192
- if (node.relation !== undefined) {
193
- result.relation = this.transform(node.relation, context);
194
- }
195
- if (node.cols !== undefined) {
196
- result.cols = Array.isArray(node.cols)
197
- ? node.cols.map(item => this.transform(item, context))
198
- : this.transform(node.cols, context);
199
- }
200
- if (node.selectStmt !== undefined) {
201
- result.selectStmt = this.transform(node.selectStmt, context);
202
- }
203
- if (node.onConflictClause !== undefined) {
204
- result.onConflictClause = this.transform(node.onConflictClause, context);
205
- }
206
- if (node.returningList !== undefined) {
207
- result.returningList = Array.isArray(node.returningList)
208
- ? node.returningList.map(item => this.transform(item, context))
209
- : this.transform(node.returningList, context);
210
- }
211
- if (node.withClause !== undefined) {
212
- result.withClause = this.transform(node.withClause, context);
213
- }
214
- if (node.override !== undefined) {
215
- result.override = node.override;
216
- }
217
- return { InsertStmt: result };
218
- }
219
- UpdateStmt(node, context) {
220
- const result = {};
221
- if (node.relation !== undefined) {
222
- result.relation = this.transform(node.relation, context);
223
- }
224
- if (node.targetList !== undefined) {
225
- result.targetList = Array.isArray(node.targetList)
226
- ? node.targetList.map(item => this.transform(item, context))
227
- : this.transform(node.targetList, context);
228
- }
229
- if (node.whereClause !== undefined) {
230
- result.whereClause = this.transform(node.whereClause, context);
231
- }
232
- if (node.fromClause !== undefined) {
233
- result.fromClause = Array.isArray(node.fromClause)
234
- ? node.fromClause.map(item => this.transform(item, context))
235
- : this.transform(node.fromClause, context);
236
- }
237
- if (node.returningList !== undefined) {
238
- result.returningList = Array.isArray(node.returningList)
239
- ? node.returningList.map(item => this.transform(item, context))
240
- : this.transform(node.returningList, context);
241
- }
242
- if (node.withClause !== undefined) {
243
- result.withClause = this.transform(node.withClause, context);
244
- }
245
- return { UpdateStmt: result };
246
- }
247
- DeleteStmt(node, context) {
248
- const result = {};
249
- if (node.relation !== undefined) {
250
- result.relation = this.transform(node.relation, context);
251
- }
252
- if (node.usingClause !== undefined) {
253
- result.usingClause = Array.isArray(node.usingClause)
254
- ? node.usingClause.map(item => this.transform(item, context))
255
- : this.transform(node.usingClause, context);
256
- }
257
- if (node.whereClause !== undefined) {
258
- result.whereClause = this.transform(node.whereClause, context);
259
- }
260
- if (node.returningList !== undefined) {
261
- result.returningList = Array.isArray(node.returningList)
262
- ? node.returningList.map(item => this.transform(item, context))
263
- : this.transform(node.returningList, context);
264
- }
265
- if (node.withClause !== undefined) {
266
- result.withClause = this.transform(node.withClause, context);
267
- }
268
- return { DeleteStmt: result };
269
- }
270
- WithClause(node, context) {
271
- const result = {};
272
- if (node.ctes !== undefined) {
273
- const cteContext = { ...context, inCTE: true };
274
- result.ctes = Array.isArray(node.ctes)
275
- ? node.ctes.map(item => this.transform(item, cteContext))
276
- : this.transform(node.ctes, cteContext);
277
- }
278
- if (node.recursive !== undefined) {
279
- result.recursive = node.recursive;
280
- }
281
- if (node.location !== undefined) {
282
- result.location = node.location;
283
- }
284
- return { WithClause: result };
285
- }
286
- ResTarget(node, context) {
287
- const result = {};
288
- if (node.name !== undefined) {
289
- result.name = node.name;
290
- }
291
- if (node.indirection !== undefined) {
292
- result.indirection = Array.isArray(node.indirection)
293
- ? node.indirection.map(item => this.transform(item, context))
294
- : this.transform(node.indirection, context);
295
- }
296
- if (node.val !== undefined) {
297
- result.val = this.transform(node.val, context);
298
- }
299
- if (node.location !== undefined) {
300
- result.location = node.location;
301
- }
302
- return { ResTarget: result };
303
- }
304
- BoolExpr(node, context) {
305
- const result = {};
306
- if (node.boolop !== undefined) {
307
- result.boolop = node.boolop;
308
- }
309
- if (node.args !== undefined) {
310
- result.args = Array.isArray(node.args)
311
- ? node.args.map(item => this.transform(item, context))
312
- : this.transform(node.args, context);
313
- }
314
- if (node.location !== undefined) {
315
- result.location = node.location;
316
- }
317
- return { BoolExpr: result };
318
- }
319
- FuncCall(node, context) {
320
- const result = {};
321
- if (node.funcname !== undefined) {
322
- result.funcname = Array.isArray(node.funcname)
323
- ? node.funcname.map(item => this.transform(item, context))
324
- : this.transform(node.funcname, context);
325
- }
326
- if (node.args !== undefined) {
327
- result.args = Array.isArray(node.args)
328
- ? node.args.map(item => this.transform(item, context))
329
- : this.transform(node.args, context);
330
- }
331
- if (node.agg_order !== undefined) {
332
- result.agg_order = Array.isArray(node.agg_order)
333
- ? node.agg_order.map(item => this.transform(item, context))
334
- : this.transform(node.agg_order, context);
335
- }
336
- if (node.agg_filter !== undefined) {
337
- result.agg_filter = this.transform(node.agg_filter, context);
338
- }
339
- if (node.agg_within_group !== undefined) {
340
- result.agg_within_group = node.agg_within_group;
341
- }
342
- if (node.agg_star !== undefined) {
343
- result.agg_star = node.agg_star;
344
- }
345
- if (node.agg_distinct !== undefined) {
346
- result.agg_distinct = node.agg_distinct;
347
- }
348
- if (node.func_variadic !== undefined) {
349
- result.func_variadic = node.func_variadic;
350
- }
351
- if (node.over !== undefined) {
352
- result.over = this.transform(node.over, context);
353
- }
354
- if (node.location !== undefined) {
355
- result.location = node.location;
356
- }
357
- const funcformatValue = this.getFuncformatValue(node, result.funcname, context);
358
- result.funcformat = funcformatValue;
359
- return { FuncCall: result };
360
- }
361
- FuncExpr(node, context) {
362
- return { FuncExpr: node };
363
- }
364
- A_Const(node, context) {
365
- return { A_Const: node };
366
- }
367
- ColumnRef(node, context) {
368
- return { ColumnRef: node };
369
- }
370
- isInCreateDomainContext(context) {
371
- return context.parentNodeTypes.includes('CreateDomainStmt');
372
- }
373
- isInTypeCastContext(context) {
374
- return context.parentNodeTypes.includes('TypeCast');
375
- }
376
- isInCreateTableContext(context) {
377
- return context.parentNodeTypes.includes('ColumnDef');
378
- }
379
- isInValuesContext(context) {
380
- return context.inValuesClause === true;
381
- }
382
- isInSimpleSelectTypeCastContext(context) {
383
- return context.parentNodeTypes.includes('TypeCast') &&
384
- context.parentNodeTypes.includes('ResTarget') &&
385
- !this.isInValuesContext(context);
386
- }
387
- shouldAddPgCatalogPrefix(context) {
388
- const hasSelectStmt = context.parentNodeTypes.includes('SelectStmt');
389
- const hasWithClause = context.parentNodeTypes.includes('WithClause');
390
- const hasCommonTableExpr = context.parentNodeTypes.includes('CommonTableExpr');
391
- return hasSelectStmt && !hasWithClause && !hasCommonTableExpr;
392
- }
393
- TypeName(node, context) {
394
- const result = {};
395
- if (node.names !== undefined) {
396
- let names = Array.isArray(node.names)
397
- ? node.names.map(item => this.transform(item, context))
398
- : this.transform(node.names, context);
399
- // Add pg_catalog prefix for JSON types in CREATE TABLE contexts
400
- if (Array.isArray(names) && names.length === 1) {
401
- const firstElement = names[0];
402
- if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
403
- const typeNameStr = firstElement.String.str || firstElement.String.sval;
404
- if (typeNameStr === 'json') {
405
- const hasCreateStmt = context.parentNodeTypes.includes('CreateStmt');
406
- const hasCompositeTypeStmt = context.parentNodeTypes.includes('CompositeTypeStmt');
407
- const hasRangeFunction = context.parentNodeTypes.includes('RangeFunction');
408
- const hasCreateDomainStmt = context.parentNodeTypes.includes('CreateDomainStmt');
409
- const hasColumnDef = context.parentNodeTypes.includes('ColumnDef');
410
- if ((hasCreateStmt || hasCompositeTypeStmt || hasRangeFunction) && hasColumnDef) {
411
- const pgCatalogElement = {
412
- String: {
413
- sval: 'pg_catalog'
414
- }
415
- };
416
- names = [pgCatalogElement, firstElement];
417
- }
418
- else if (hasCreateDomainStmt) {
419
- const pgCatalogElement = {
420
- String: {
421
- sval: 'pg_catalog'
422
- }
423
- };
424
- names = [pgCatalogElement, firstElement];
425
- }
426
- }
427
- }
428
- }
429
- result.names = names;
430
- }
431
- if (node.typeOid !== undefined) {
432
- result.typeOid = node.typeOid;
433
- }
434
- if (node.setof !== undefined) {
435
- result.setof = node.setof;
436
- }
437
- if (node.pct_type !== undefined) {
438
- result.pct_type = node.pct_type;
439
- }
440
- if (node.typmods !== undefined) {
441
- result.typmods = Array.isArray(node.typmods)
442
- ? node.typmods.map(item => this.transform(item, context))
443
- : this.transform(node.typmods, context);
444
- }
445
- if (node.typemod !== undefined) {
446
- result.typemod = node.typemod;
447
- }
448
- if (node.arrayBounds !== undefined) {
449
- result.arrayBounds = Array.isArray(node.arrayBounds)
450
- ? node.arrayBounds.map(item => this.transform(item, context))
451
- : this.transform(node.arrayBounds, context);
452
- }
453
- if (node.location !== undefined) {
454
- result.location = node.location;
455
- }
456
- return { TypeName: result };
457
- }
458
- Alias(node, context) {
459
- return { Alias: node };
460
- }
461
- RangeVar(node, context) {
462
- const result = {};
463
- if (node.catalogname !== undefined) {
464
- result.catalogname = node.catalogname;
465
- }
466
- if (node.schemaname !== undefined) {
467
- result.schemaname = node.schemaname;
468
- }
469
- if (node.relname !== undefined) {
470
- result.relname = node.relname;
471
- }
472
- if (node.inh !== undefined) {
473
- result.inh = node.inh;
474
- }
475
- if (node.relpersistence !== undefined) {
476
- result.relpersistence = node.relpersistence;
477
- }
478
- if (node.alias !== undefined) {
479
- result.alias = this.transform(node.alias, context);
480
- }
481
- if (node.location !== undefined) {
482
- result.location = node.location;
483
- }
484
- return { RangeVar: result };
485
- }
486
- A_ArrayExpr(node, context) {
487
- return { A_ArrayExpr: node };
488
- }
489
- A_Indices(node, context) {
490
- return { A_Indices: node };
491
- }
492
- A_Indirection(node, context) {
493
- return { A_Indirection: node };
494
- }
495
- A_Star(node, context) {
496
- return { A_Star: node };
497
- }
498
- CaseExpr(node, context) {
499
- return { CaseExpr: node };
500
- }
501
- CoalesceExpr(node, context) {
502
- return { CoalesceExpr: node };
503
- }
504
- TypeCast(node, context) {
505
- const result = {};
506
- if (node.arg !== undefined) {
507
- result.arg = this.transform(node.arg, context);
508
- }
509
- if (node.typeName !== undefined) {
510
- let typeName = this.transform(node.typeName, context);
511
- // Add pg_catalog prefix for JSON types in simple SELECT contexts, but NOT in WITH clauses
512
- if (typeName && typeName.names && Array.isArray(typeName.names) && typeName.names.length === 1) {
513
- const firstElement = typeName.names[0];
514
- if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
515
- const typeNameStr = firstElement.String.str || firstElement.String.sval;
516
- if (typeNameStr === 'json') {
517
- const hasSelectStmt = context.parentNodeTypes.includes('SelectStmt');
518
- const hasResTarget = context.parentNodeTypes.includes('ResTarget');
519
- const hasList = context.parentNodeTypes.includes('List');
520
- const hasA_Expr = context.parentNodeTypes.includes('A_Expr');
521
- const hasWithClause = context.parentNodeTypes.includes('WithClause');
522
- const hasCommonTableExpr = context.parentNodeTypes.includes('CommonTableExpr');
523
- if (((hasSelectStmt && hasResTarget) || (hasSelectStmt && hasList) || hasA_Expr) && !hasWithClause && !hasCommonTableExpr) {
524
- const pgCatalogElement = {
525
- String: {
526
- sval: 'pg_catalog'
527
- }
528
- };
529
- typeName.names = [pgCatalogElement, firstElement];
530
- }
531
- }
532
- }
533
- }
534
- result.typeName = typeName;
535
- }
536
- if (node.location !== undefined) {
537
- result.location = node.location;
538
- }
539
- return { TypeCast: result };
540
- }
541
- CollateClause(node, context) {
542
- return { CollateClause: node };
543
- }
544
- BooleanTest(node, context) {
545
- return { BooleanTest: node };
546
- }
547
- NullTest(node, context) {
548
- return { NullTest: node };
549
- }
550
- String(node, context) {
551
- return { String: node };
552
- }
553
- Integer(node, context) {
554
- return { Integer: node };
555
- }
556
- Float(node, context) {
557
- return { Float: node };
558
- }
559
- Boolean(node, context) {
560
- return { Boolean: node };
561
- }
562
- BitString(node, context) {
563
- return { BitString: node };
564
- }
565
- // NOTE: there is no Null type in PG17
566
- Null(node, context) {
567
- return { Null: node };
568
- }
569
- List(node, context) {
570
- const result = {};
571
- if (node.items !== undefined) {
572
- result.items = Array.isArray(node.items)
573
- ? node.items.map(item => this.transform(item, context))
574
- : this.transform(node.items, context);
575
- }
576
- return { List: result };
577
- }
578
- CreateStmt(node, context) {
579
- const result = {};
580
- if (node.relation !== undefined) {
581
- result.relation = this.transform(node.relation, context);
582
- }
583
- if (node.tableElts !== undefined) {
584
- result.tableElts = Array.isArray(node.tableElts)
585
- ? node.tableElts.map(item => this.transform(item, context))
586
- : this.transform(node.tableElts, context);
587
- }
588
- if (node.inhRelations !== undefined) {
589
- result.inhRelations = Array.isArray(node.inhRelations)
590
- ? node.inhRelations.map(item => this.transform(item, context))
591
- : this.transform(node.inhRelations, context);
592
- }
593
- if (node.partbound !== undefined) {
594
- result.partbound = this.transform(node.partbound, context);
595
- }
596
- if (node.partspec !== undefined) {
597
- result.partspec = this.transform(node.partspec, context);
598
- }
599
- if (node.ofTypename !== undefined) {
600
- result.ofTypename = this.transform(node.ofTypename, context);
601
- }
602
- if (node.constraints !== undefined) {
603
- result.constraints = Array.isArray(node.constraints)
604
- ? node.constraints.map(item => this.transform(item, context))
605
- : this.transform(node.constraints, context);
606
- }
607
- if (node.options !== undefined) {
608
- result.options = Array.isArray(node.options)
609
- ? node.options.map(item => this.transform(item, context))
610
- : this.transform(node.options, context);
611
- }
612
- if (node.oncommit !== undefined) {
613
- result.oncommit = node.oncommit;
614
- }
615
- if (node.tablespacename !== undefined) {
616
- result.tablespacename = node.tablespacename;
617
- }
618
- if (node.accessMethod !== undefined) {
619
- result.accessMethod = node.accessMethod;
620
- }
621
- if (node.if_not_exists !== undefined) {
622
- result.if_not_exists = node.if_not_exists;
623
- }
624
- return { CreateStmt: result };
625
- }
626
- ColumnDef(node, context) {
627
- const result = {};
628
- if (node.colname !== undefined) {
629
- result.colname = node.colname;
630
- }
631
- if (node.typeName !== undefined) {
632
- const transformedTypeName = this.TypeName(node.typeName, context);
633
- result.typeName = transformedTypeName.TypeName;
634
- }
635
- if (node.inhcount !== undefined) {
636
- result.inhcount = node.inhcount;
637
- }
638
- if (node.is_local !== undefined) {
639
- result.is_local = node.is_local;
640
- }
641
- if (node.is_not_null !== undefined) {
642
- result.is_not_null = node.is_not_null;
643
- }
644
- if (node.is_from_type !== undefined) {
645
- result.is_from_type = node.is_from_type;
646
- }
647
- if (node.storage !== undefined) {
648
- result.storage = node.storage;
649
- }
650
- if (node.raw_default !== undefined) {
651
- result.raw_default = this.transform(node.raw_default, context);
652
- }
653
- if (node.cooked_default !== undefined) {
654
- result.cooked_default = this.transform(node.cooked_default, context);
655
- }
656
- if (node.identity !== undefined) {
657
- result.identity = node.identity;
658
- }
659
- if (node.identitySequence !== undefined) {
660
- result.identitySequence = this.transform(node.identitySequence, context);
661
- }
662
- if (node.generated !== undefined) {
663
- result.generated = node.generated;
664
- }
665
- if (node.collClause !== undefined) {
666
- result.collClause = this.transform(node.collClause, context);
667
- }
668
- if (node.collOid !== undefined) {
669
- result.collOid = node.collOid;
670
- }
671
- if (node.constraints !== undefined) {
672
- result.constraints = Array.isArray(node.constraints)
673
- ? node.constraints.map(item => this.transform(item, context))
674
- : this.transform(node.constraints, context);
675
- }
676
- if (node.fdwoptions !== undefined) {
677
- result.fdwoptions = Array.isArray(node.fdwoptions)
678
- ? node.fdwoptions.map(item => this.transform(item, context))
679
- : this.transform(node.fdwoptions, context);
680
- }
681
- if (node.location !== undefined) {
682
- result.location = node.location;
683
- }
684
- return { ColumnDef: result };
685
- }
686
- Constraint(node, context) {
687
- return { Constraint: node };
688
- }
689
- SubLink(node, context) {
690
- return { SubLink: node };
691
- }
692
- CaseWhen(node, context) {
693
- return { CaseWhen: node };
694
- }
695
- WindowDef(node, context) {
696
- return { WindowDef: node };
697
- }
698
- SortBy(node, context) {
699
- return { SortBy: node };
700
- }
701
- GroupingSet(node, context) {
702
- return { GroupingSet: node };
703
- }
704
- CommonTableExpr(node, context) {
705
- const result = {};
706
- if (node.ctename !== undefined) {
707
- result.ctename = node.ctename;
708
- }
709
- if (node.aliascolnames !== undefined) {
710
- result.aliascolnames = Array.isArray(node.aliascolnames)
711
- ? node.aliascolnames.map(item => this.transform(item, context))
712
- : this.transform(node.aliascolnames, context);
713
- }
714
- if (node.ctematerialized !== undefined) {
715
- result.ctematerialized = node.ctematerialized;
716
- }
717
- if (node.ctequery !== undefined) {
718
- result.ctequery = this.transform(node.ctequery, context);
719
- }
720
- if (node.search_clause !== undefined) {
721
- result.search_clause = this.transform(node.search_clause, context);
722
- }
723
- if (node.cycle_clause !== undefined) {
724
- result.cycle_clause = this.transform(node.cycle_clause, context);
725
- }
726
- if (node.location !== undefined) {
727
- result.location = node.location;
728
- }
729
- return { CommonTableExpr: result };
730
- }
731
- ParamRef(node, context) {
732
- return { ParamRef: node };
733
- }
734
- LockingClause(node, context) {
735
- return { LockingClause: node };
736
- }
737
- MinMaxExpr(node, context) {
738
- return { MinMaxExpr: node };
739
- }
740
- RowExpr(node, context) {
741
- return { RowExpr: node };
742
- }
743
- OpExpr(node, context) {
744
- return { OpExpr: node };
745
- }
746
- DistinctExpr(node, context) {
747
- return { DistinctExpr: node };
748
- }
749
- NullIfExpr(node, context) {
750
- return { NullIfExpr: node };
751
- }
752
- ScalarArrayOpExpr(node, context) {
753
- return { ScalarArrayOpExpr: node };
754
- }
755
- Aggref(node, context) {
756
- return { Aggref: node };
757
- }
758
- WindowFunc(node, context) {
759
- return { WindowFunc: node };
760
- }
761
- FieldSelect(node, context) {
762
- return { FieldSelect: node };
763
- }
764
- RelabelType(node, context) {
765
- return { RelabelType: node };
766
- }
767
- CoerceViaIO(node, context) {
768
- return { CoerceViaIO: node };
769
- }
770
- ArrayCoerceExpr(node, context) {
771
- return { ArrayCoerceExpr: node };
772
- }
773
- ConvertRowtypeExpr(node, context) {
774
- return { ConvertRowtypeExpr: node };
775
- }
776
- NamedArgExpr(node, context) {
777
- return { NamedArgExpr: node };
778
- }
779
- ViewStmt(node, context) {
780
- return { ViewStmt: node };
781
- }
782
- IndexStmt(node, context) {
783
- return { IndexStmt: node };
784
- }
785
- IndexElem(node, context) {
786
- return { IndexElem: node };
787
- }
788
- PartitionElem(node, context) {
789
- return { PartitionElem: node };
790
- }
791
- PartitionCmd(node, context) {
792
- return { PartitionCmd: node };
793
- }
794
- JoinExpr(node, context) {
795
- return { JoinExpr: node };
796
- }
797
- FromExpr(node, context) {
798
- return { FromExpr: node };
799
- }
800
- TransactionStmt(node, context) {
801
- return { TransactionStmt: node };
802
- }
803
- VariableSetStmt(node, context) {
804
- return { VariableSetStmt: node };
805
- }
806
- VariableShowStmt(node, context) {
807
- return { VariableShowStmt: node };
808
- }
809
- CreateSchemaStmt(node, context) {
810
- return { CreateSchemaStmt: node };
811
- }
812
- RoleSpec(node, context) {
813
- return { RoleSpec: node };
814
- }
815
- DropStmt(node, context) {
816
- return { DropStmt: node };
817
- }
818
- TruncateStmt(node, context) {
819
- return { TruncateStmt: node };
820
- }
821
- ReturnStmt(node, context) {
822
- return { ReturnStmt: node };
823
- }
824
- PLAssignStmt(node, context) {
825
- return { PLAssignStmt: node };
826
- }
827
- CopyStmt(node, context) {
828
- return { CopyStmt: node };
829
- }
830
- AlterTableStmt(node, context) {
831
- return { AlterTableStmt: node };
832
- }
833
- AlterTableCmd(node, context) {
834
- return { AlterTableCmd: node };
835
- }
836
- CreateFunctionStmt(node, context) {
837
- return { CreateFunctionStmt: node };
838
- }
839
- FunctionParameter(node, context) {
840
- return { FunctionParameter: node };
841
- }
842
- CreateEnumStmt(node, context) {
843
- return { CreateEnumStmt: node };
844
- }
845
- CreateDomainStmt(node, context) {
846
- const result = {};
847
- if (node.domainname !== undefined) {
848
- result.domainname = Array.isArray(node.domainname)
849
- ? node.domainname.map(item => this.transform(item, context))
850
- : this.transform(node.domainname, context);
851
- }
852
- if (node.typeName !== undefined) {
853
- const transformedTypeName = this.TypeName(node.typeName, context);
854
- result.typeName = transformedTypeName.TypeName;
855
- }
856
- if (node.collClause !== undefined) {
857
- result.collClause = this.transform(node.collClause, context);
858
- }
859
- if (node.constraints !== undefined) {
860
- result.constraints = Array.isArray(node.constraints)
861
- ? node.constraints.map(item => this.transform(item, context))
862
- : this.transform(node.constraints, context);
863
- }
864
- return { CreateDomainStmt: result };
865
- }
866
- CreateRoleStmt(node, context) {
867
- return { CreateRoleStmt: node };
868
- }
869
- DefElem(node, context) {
870
- return { DefElem: node };
871
- }
872
- CreateTableSpaceStmt(node, context) {
873
- return { CreateTableSpaceStmt: node };
874
- }
875
- DropTableSpaceStmt(node, context) {
876
- return { DropTableSpaceStmt: node };
877
- }
878
- AlterTableSpaceOptionsStmt(node, context) {
879
- return { AlterTableSpaceOptionsStmt: node };
880
- }
881
- CreateExtensionStmt(node, context) {
882
- return { CreateExtensionStmt: node };
883
- }
884
- AlterExtensionStmt(node, context) {
885
- return { AlterExtensionStmt: node };
886
- }
887
- CreateFdwStmt(node, context) {
888
- return { CreateFdwStmt: node };
889
- }
890
- SetOperationStmt(node, context) {
891
- return { SetOperationStmt: node };
892
- }
893
- ReplicaIdentityStmt(node, context) {
894
- return { ReplicaIdentityStmt: node };
895
- }
896
- AlterCollationStmt(node, context) {
897
- return { AlterCollationStmt: node };
898
- }
899
- AlterDomainStmt(node, context) {
900
- return { AlterDomainStmt: node };
901
- }
902
- PrepareStmt(node, context) {
903
- return { PrepareStmt: node };
904
- }
905
- ExecuteStmt(node, context) {
906
- return { ExecuteStmt: node };
907
- }
908
- DeallocateStmt(node, context) {
909
- const result = {};
910
- if (node.name !== undefined) {
911
- result.name = node.name;
912
- }
913
- if (node.name === undefined || node.name === null) {
914
- result.isall = true;
915
- }
916
- return { DeallocateStmt: result };
917
- }
918
- NotifyStmt(node, context) {
919
- return { NotifyStmt: node };
920
- }
921
- ListenStmt(node, context) {
922
- return { ListenStmt: node };
923
- }
924
- UnlistenStmt(node, context) {
925
- return { UnlistenStmt: node };
926
- }
927
- CheckPointStmt(node, context) {
928
- return { CheckPointStmt: node };
929
- }
930
- LoadStmt(node, context) {
931
- return { LoadStmt: node };
932
- }
933
- DiscardStmt(node, context) {
934
- return { DiscardStmt: node };
935
- }
936
- CommentStmt(node, context) {
937
- return { CommentStmt: node };
938
- }
939
- LockStmt(node, context) {
940
- return { LockStmt: node };
941
- }
942
- CreatePolicyStmt(node, context) {
943
- return { CreatePolicyStmt: node };
944
- }
945
- AlterPolicyStmt(node, context) {
946
- return { AlterPolicyStmt: node };
947
- }
948
- CreateUserMappingStmt(node, context) {
949
- return { CreateUserMappingStmt: node };
950
- }
951
- CreateStatsStmt(node, context) {
952
- return { CreateStatsStmt: node };
953
- }
954
- StatsElem(node, context) {
955
- return { StatsElem: node };
956
- }
957
- CreatePublicationStmt(node, context) {
958
- return { CreatePublicationStmt: node };
959
- }
960
- CreateSubscriptionStmt(node, context) {
961
- return { CreateSubscriptionStmt: node };
962
- }
963
- AlterPublicationStmt(node, context) {
964
- return { AlterPublicationStmt: node };
965
- }
966
- AlterSubscriptionStmt(node, context) {
967
- return { AlterSubscriptionStmt: node };
968
- }
969
- DropSubscriptionStmt(node, context) {
970
- return { DropSubscriptionStmt: node };
971
- }
972
- DoStmt(node, context) {
973
- return { DoStmt: node };
974
- }
975
- InlineCodeBlock(node, context) {
976
- return { InlineCodeBlock: node };
977
- }
978
- CallContext(node, context) {
979
- return { CallContext: node };
980
- }
981
- ConstraintsSetStmt(node, context) {
982
- return { ConstraintsSetStmt: node };
983
- }
984
- AlterSystemStmt(node, context) {
985
- return { AlterSystemStmt: node };
986
- }
987
- VacuumRelation(node, context) {
988
- return { VacuumRelation: node };
989
- }
990
- DropOwnedStmt(node, context) {
991
- return { DropOwnedStmt: node };
992
- }
993
- ReassignOwnedStmt(node, context) {
994
- return { ReassignOwnedStmt: node };
995
- }
996
- AlterTSDictionaryStmt(node, context) {
997
- return { AlterTSDictionaryStmt: node };
998
- }
999
- AlterTSConfigurationStmt(node, context) {
1000
- return { AlterTSConfigurationStmt: node };
1001
- }
1002
- ClosePortalStmt(node, context) {
1003
- return { ClosePortalStmt: node };
1004
- }
1005
- FetchStmt(node, context) {
1006
- return { FetchStmt: node };
1007
- }
1008
- AlterStatsStmt(node, context) {
1009
- return { AlterStatsStmt: node };
1010
- }
1011
- ObjectWithArgs(node, context) {
1012
- return { ObjectWithArgs: node };
1013
- }
1014
- AlterOperatorStmt(node, context) {
1015
- return { AlterOperatorStmt: node };
1016
- }
1017
- AlterFdwStmt(node, context) {
1018
- return { AlterFdwStmt: node };
1019
- }
1020
- CreateForeignServerStmt(node, context) {
1021
- return { CreateForeignServerStmt: node };
1022
- }
1023
- AlterForeignServerStmt(node, context) {
1024
- return { AlterForeignServerStmt: node };
1025
- }
1026
- AlterUserMappingStmt(node, context) {
1027
- return { AlterUserMappingStmt: node };
1028
- }
1029
- DropUserMappingStmt(node, context) {
1030
- return { DropUserMappingStmt: node };
1031
- }
1032
- ImportForeignSchemaStmt(node, context) {
1033
- return { ImportForeignSchemaStmt: node };
1034
- }
1035
- ClusterStmt(node, context) {
1036
- return { ClusterStmt: node };
1037
- }
1038
- VacuumStmt(node, context) {
1039
- return { VacuumStmt: node };
1040
- }
1041
- ExplainStmt(node, context) {
1042
- return { ExplainStmt: node };
1043
- }
1044
- ReindexStmt(node, context) {
1045
- return { ReindexStmt: node };
1046
- }
1047
- CallStmt(node, context) {
1048
- return { CallStmt: node };
1049
- }
1050
- CreatedbStmt(node, context) {
1051
- return { CreatedbStmt: node };
1052
- }
1053
- DropdbStmt(node, context) {
1054
- return { DropdbStmt: node };
1055
- }
1056
- RenameStmt(node, context) {
1057
- return { RenameStmt: node };
1058
- }
1059
- AlterOwnerStmt(node, context) {
1060
- return { AlterOwnerStmt: node };
1061
- }
1062
- GrantStmt(node, context) {
1063
- return { GrantStmt: node };
1064
- }
1065
- GrantRoleStmt(node, context) {
1066
- return { GrantRoleStmt: node };
1067
- }
1068
- SecLabelStmt(node, context) {
1069
- return { SecLabelStmt: node };
1070
- }
1071
- AlterDefaultPrivilegesStmt(node, context) {
1072
- return { AlterDefaultPrivilegesStmt: node };
1073
- }
1074
- CreateConversionStmt(node, context) {
1075
- return { CreateConversionStmt: node };
1076
- }
1077
- CreateCastStmt(node, context) {
1078
- return { CreateCastStmt: node };
1079
- }
1080
- CreatePLangStmt(node, context) {
1081
- return { CreatePLangStmt: node };
1082
- }
1083
- CreateTransformStmt(node, context) {
1084
- return { CreateTransformStmt: node };
1085
- }
1086
- CreateTrigStmt(node, context) {
1087
- return { CreateTrigStmt: node };
1088
- }
1089
- TriggerTransition(node, context) {
1090
- return { TriggerTransition: node };
1091
- }
1092
- CreateEventTrigStmt(node, context) {
1093
- return { CreateEventTrigStmt: node };
1094
- }
1095
- AlterEventTrigStmt(node, context) {
1096
- return { AlterEventTrigStmt: node };
1097
- }
1098
- CreateOpClassStmt(node, context) {
1099
- return { CreateOpClassStmt: node };
1100
- }
1101
- CreateOpFamilyStmt(node, context) {
1102
- return { CreateOpFamilyStmt: node };
1103
- }
1104
- AlterOpFamilyStmt(node, context) {
1105
- return { AlterOpFamilyStmt: node };
1106
- }
1107
- MergeStmt(node, context) {
1108
- const result = {};
1109
- if (node.relation !== undefined) {
1110
- result.relation = node.relation;
1111
- }
1112
- if (node.sourceRelation !== undefined) {
1113
- result.sourceRelation = this.transform(node.sourceRelation, context);
1114
- }
1115
- if (node.joinCondition !== undefined) {
1116
- result.joinCondition = this.transform(node.joinCondition, context);
1117
- }
1118
- if (node.mergeWhenClauses !== undefined) {
1119
- result.mergeWhenClauses = Array.isArray(node.mergeWhenClauses)
1120
- ? node.mergeWhenClauses.map(item => this.transform(item, context))
1121
- : this.transform(node.mergeWhenClauses, context);
1122
- }
1123
- if (node.withClause !== undefined) {
1124
- result.withClause = this.WithClause(node.withClause, context);
1125
- }
1126
- return { MergeStmt: result };
1127
- }
1128
- MergeWhenClause(node, context) {
1129
- const result = {};
1130
- // v17 replaces the boolean matched with matchKind
1131
- result.matchKind = node.matched ? 'MERGE_WHEN_MATCHED' : 'MERGE_WHEN_NOT_MATCHED_BY_TARGET';
1132
- if (node.commandType !== undefined) {
1133
- result.commandType = node.commandType;
1134
- }
1135
- if (node.override !== undefined) {
1136
- result.override = node.override;
1137
- }
1138
- if (node.condition !== undefined) {
1139
- result.condition = this.transform(node.condition, context);
1140
- }
1141
- if (node.targetList !== undefined) {
1142
- result.targetList = Array.isArray(node.targetList)
1143
- ? node.targetList.map(item => this.transform(item, context))
1144
- : this.transform(node.targetList, context);
1145
- }
1146
- if (node.values !== undefined) {
1147
- result.values = Array.isArray(node.values)
1148
- ? node.values.map(item => this.transform(item, context))
1149
- : this.transform(node.values, context);
1150
- }
1151
- return { MergeWhenClause: result };
1152
- }
1153
- AlterTableMoveAllStmt(node, context) {
1154
- return { AlterTableMoveAllStmt: node };
1155
- }
1156
- CreateSeqStmt(node, context) {
1157
- return { CreateSeqStmt: node };
1158
- }
1159
- AlterSeqStmt(node, context) {
1160
- return { AlterSeqStmt: node };
1161
- }
1162
- CompositeTypeStmt(node, context) {
1163
- const result = {};
1164
- if (node.typevar !== undefined) {
1165
- result.typevar = this.transform(node.typevar, context);
1166
- }
1167
- if (node.coldeflist !== undefined) {
1168
- result.coldeflist = Array.isArray(node.coldeflist)
1169
- ? node.coldeflist.map(item => this.transform(item, context))
1170
- : this.transform(node.coldeflist, context);
1171
- }
1172
- return { CompositeTypeStmt: result };
1173
- }
1174
- CreateRangeStmt(node, context) {
1175
- return { CreateRangeStmt: node };
1176
- }
1177
- AlterEnumStmt(node, context) {
1178
- return { AlterEnumStmt: node };
1179
- }
1180
- AlterTypeStmt(node, context) {
1181
- return { AlterTypeStmt: node };
1182
- }
1183
- AlterRoleStmt(node, context) {
1184
- return { AlterRoleStmt: node };
1185
- }
1186
- DropRoleStmt(node, context) {
1187
- return { DropRoleStmt: node };
1188
- }
1189
- // NOTE PG 17 has a no CreateAggregateStmt?
1190
- // In PostgreSQL 17, the CreateAggregateStmt has been removed from the backend parser infrastructure and replaced by CreateFunctionStmt with a kind = OBJECT_AGGREGATE variant.
1191
- CreateAggregateStmt(node, context) {
1192
- return { CreateAggregateStmt: node };
1193
- }
1194
- CreateTableAsStmt(node, context) {
1195
- return { CreateTableAsStmt: node };
1196
- }
1197
- RefreshMatViewStmt(node, context) {
1198
- return { RefreshMatViewStmt: node };
1199
- }
1200
- AccessPriv(node, context) {
1201
- return { AccessPriv: node };
1202
- }
1203
- DefineStmt(node, context) {
1204
- return { DefineStmt: node };
1205
- }
1206
- AlterDatabaseStmt(node, context) {
1207
- return { AlterDatabaseStmt: node };
1208
- }
1209
- AlterDatabaseRefreshCollStmt(node, context) {
1210
- return { AlterDatabaseRefreshCollStmt: node };
1211
- }
1212
- AlterDatabaseSetStmt(node, context) {
1213
- return { AlterDatabaseSetStmt: node };
1214
- }
1215
- DeclareCursorStmt(node, context) {
1216
- return { DeclareCursorStmt: node };
1217
- }
1218
- PublicationObjSpec(node, context) {
1219
- return { PublicationObjSpec: node };
1220
- }
1221
- PublicationTable(node, context) {
1222
- return { PublicationTable: node };
1223
- }
1224
- CreateAmStmt(node, context) {
1225
- return { CreateAmStmt: node };
1226
- }
1227
- IntoClause(node, context) {
1228
- return { IntoClause: node };
1229
- }
1230
- OnConflictExpr(node, context) {
1231
- return { OnConflictExpr: node };
1232
- }
1233
- ScanToken(node, context) {
1234
- return { ScanToken: node };
1235
- }
1236
- CreateOpClassItem(node, context) {
1237
- return { CreateOpClassItem: node };
1238
- }
1239
- Var(node, context) {
1240
- return { Var: node };
1241
- }
1242
- TableFunc(node, context) {
1243
- return { TableFunc: node };
1244
- }
1245
- RangeTableFunc(node, context) {
1246
- return { RangeTableFunc: node };
1247
- }
1248
- RangeTableFuncCol(node, context) {
1249
- return { RangeTableFuncCol: node };
1250
- }
1251
- JsonArrayQueryConstructor(node, context) {
1252
- return { JsonArrayQueryConstructor: node };
1253
- }
1254
- RangeFunction(node, context) {
1255
- const result = {};
1256
- if (node.lateral !== undefined) {
1257
- result.lateral = node.lateral;
1258
- }
1259
- if (node.ordinality !== undefined) {
1260
- result.ordinality = node.ordinality;
1261
- }
1262
- if (node.is_rowsfrom !== undefined) {
1263
- result.is_rowsfrom = node.is_rowsfrom;
1264
- }
1265
- if (node.functions !== undefined) {
1266
- result.functions = Array.isArray(node.functions)
1267
- ? node.functions.map(item => this.transform(item, context))
1268
- : this.transform(node.functions, context);
1269
- }
1270
- if (node.alias !== undefined) {
1271
- result.alias = this.transform(node.alias, context);
1272
- }
1273
- if (node.coldeflist !== undefined) {
1274
- result.coldeflist = Array.isArray(node.coldeflist)
1275
- ? node.coldeflist.map(item => this.transform(item, context))
1276
- : this.transform(node.coldeflist, context);
1277
- }
1278
- return { RangeFunction: result };
1279
- }
1280
- XmlSerialize(node, context) {
1281
- const result = {};
1282
- if (node.xmloption !== undefined) {
1283
- result.xmloption = node.xmloption;
1284
- }
1285
- if (node.expr !== undefined) {
1286
- result.expr = this.transform(node.expr, context);
1287
- }
1288
- if (node.typeName !== undefined) {
1289
- result.typeName = this.transform(node.typeName, context);
1290
- }
1291
- if (node.location !== undefined) {
1292
- result.location = node.location;
1293
- }
1294
- return { XmlSerialize: result };
1295
- }
1296
- RuleStmt(node, context) {
1297
- return { RuleStmt: node };
1298
- }
1299
- GroupingFunc(node, context) {
1300
- const result = {};
1301
- if (node.args !== undefined) {
1302
- result.args = Array.isArray(node.args)
1303
- ? node.args.map((item) => this.transform(item, context))
1304
- : this.transform(node.args, context);
1305
- }
1306
- if (node.refs !== undefined) {
1307
- result.refs = Array.isArray(node.refs)
1308
- ? node.refs.map((item) => this.transform(item, context))
1309
- : this.transform(node.refs, context);
1310
- }
1311
- if (node.agglevelsup !== undefined) {
1312
- result.agglevelsup = node.agglevelsup;
1313
- }
1314
- if (node.location !== undefined) {
1315
- result.location = node.location;
1316
- }
1317
- return { GroupingFunc: result };
1318
- }
1319
- MultiAssignRef(node, context) {
1320
- const result = {};
1321
- if (node.source !== undefined) {
1322
- result.source = this.transform(node.source, context);
1323
- }
1324
- if (node.colno !== undefined) {
1325
- result.colno = node.colno;
1326
- }
1327
- if (node.ncolumns !== undefined) {
1328
- result.ncolumns = node.ncolumns;
1329
- }
1330
- return { MultiAssignRef: result };
1331
- }
1332
- CurrentOfExpr(node, context) {
1333
- const result = {};
1334
- if (node.cursor_name !== undefined) {
1335
- result.cursor_name = node.cursor_name;
1336
- }
1337
- if (node.cursor_param !== undefined) {
1338
- result.cursor_param = node.cursor_param;
1339
- }
1340
- return { CurrentOfExpr: result };
1341
- }
1342
- TableLikeClause(node, context) {
1343
- return { TableLikeClause: node };
1344
- }
1345
- AlterFunctionStmt(node, context) {
1346
- return { AlterFunctionStmt: node };
1347
- }
1348
- AlterObjectSchemaStmt(node, context) {
1349
- return { AlterObjectSchemaStmt: node };
1350
- }
1351
- AlterRoleSetStmt(node, context) {
1352
- const result = {};
1353
- if (node.role !== undefined) {
1354
- result.role = this.transform(node.role, context);
1355
- }
1356
- if (node.database !== undefined) {
1357
- result.database = node.database;
1358
- }
1359
- if (node.setstmt !== undefined) {
1360
- result.setstmt = this.transform(node.setstmt, context);
1361
- }
1362
- return { AlterRoleSetStmt: result };
1363
- }
1364
- CreateForeignTableStmt(node, context) {
1365
- return { CreateForeignTableStmt: node };
1366
- }
1367
- getFuncformatValue(node, funcname, context) {
1368
- const functionName = this.getFunctionName(node, funcname);
1369
- if (!functionName) {
1370
- return 'COERCE_EXPLICIT_CALL';
1371
- }
1372
- const hasPgCatalogPrefix = this.hasPgCatalogPrefix(funcname);
1373
- const sqlSyntaxFunctions = [
1374
- 'trim', 'ltrim', 'rtrim', 'btrim',
1375
- 'position', 'overlay', 'substring',
1376
- 'extract', 'timezone', 'xmlexists',
1377
- 'current_date', 'current_time', 'current_timestamp',
1378
- 'localtime', 'localtimestamp', 'overlaps'
1379
- ];
1380
- // Handle specific functions that depend on pg_catalog prefix
1381
- if (functionName.toLowerCase() === 'substring') {
1382
- if (hasPgCatalogPrefix) {
1383
- return 'COERCE_SQL_SYNTAX';
1384
- }
1385
- return 'COERCE_EXPLICIT_CALL';
1386
- }
1387
- if (functionName.toLowerCase() === 'ltrim') {
1388
- if (hasPgCatalogPrefix) {
1389
- return 'COERCE_SQL_SYNTAX';
1390
- }
1391
- return 'COERCE_EXPLICIT_CALL';
1392
- }
1393
- if (functionName.toLowerCase() === 'btrim') {
1394
- if (hasPgCatalogPrefix) {
1395
- return 'COERCE_SQL_SYNTAX';
1396
- }
1397
- return 'COERCE_EXPLICIT_CALL';
1398
- }
1399
- if (functionName.toLowerCase() === 'pg_collation_for') {
1400
- if (hasPgCatalogPrefix) {
1401
- return 'COERCE_SQL_SYNTAX';
1402
- }
1403
- return 'COERCE_EXPLICIT_CALL';
1404
- }
1405
- if (sqlSyntaxFunctions.includes(functionName.toLowerCase())) {
1406
- return 'COERCE_SQL_SYNTAX';
1407
- }
1408
- return 'COERCE_EXPLICIT_CALL';
1409
- }
1410
- getFunctionName(node, funcname) {
1411
- const names = funcname || node?.funcname;
1412
- if (names && Array.isArray(names) && names.length > 0) {
1413
- const lastName = names[names.length - 1];
1414
- if (lastName && typeof lastName === 'object' && 'String' in lastName) {
1415
- return lastName.String.str || lastName.String.sval;
1416
- }
1417
- }
1418
- return null;
1419
- }
1420
- hasPgCatalogPrefix(funcname) {
1421
- if (funcname && Array.isArray(funcname) && funcname.length >= 2) {
1422
- const firstElement = funcname[0];
1423
- if (firstElement && typeof firstElement === 'object' && 'String' in firstElement) {
1424
- const prefix = firstElement.String.str || firstElement.String.sval;
1425
- return prefix === 'pg_catalog';
1426
- }
1427
- }
1428
- return false;
1429
- }
1430
- RangeTableSample(node, context) {
1431
- const result = {};
1432
- if (node.relation !== undefined) {
1433
- result.relation = this.transform(node.relation, context);
1434
- }
1435
- if (node.method !== undefined) {
1436
- result.method = Array.isArray(node.method)
1437
- ? node.method.map(item => this.transform(item, context))
1438
- : this.transform(node.method, context);
1439
- }
1440
- if (node.args !== undefined) {
1441
- result.args = Array.isArray(node.args)
1442
- ? node.args.map(item => this.transform(item, context))
1443
- : this.transform(node.args, context);
1444
- }
1445
- if (node.repeatable !== undefined) {
1446
- result.repeatable = this.transform(node.repeatable, context);
1447
- }
1448
- if (node.location !== undefined) {
1449
- result.location = node.location;
1450
- }
1451
- return { RangeTableSample: result };
1452
- }
1453
- SQLValueFunction(node, context) {
1454
- const result = {};
1455
- if (node.op !== undefined) {
1456
- result.op = node.op;
1457
- }
1458
- if (node.type !== undefined) {
1459
- result.type = node.type;
1460
- }
1461
- if (node.typmod !== undefined) {
1462
- result.typmod = node.typmod;
1463
- }
1464
- if (node.location !== undefined) {
1465
- result.location = node.location;
1466
- }
1467
- return { SQLValueFunction: result };
1468
- }
1469
- XmlExpr(node, context) {
1470
- const result = {};
1471
- if (node.op !== undefined) {
1472
- result.op = node.op;
1473
- }
1474
- if (node.name !== undefined) {
1475
- result.name = node.name;
1476
- }
1477
- if (node.named_args !== undefined) {
1478
- result.named_args = Array.isArray(node.named_args)
1479
- ? node.named_args.map(item => this.transform(item, context))
1480
- : this.transform(node.named_args, context);
1481
- }
1482
- if (node.arg_names !== undefined) {
1483
- result.arg_names = Array.isArray(node.arg_names)
1484
- ? node.arg_names.map(item => this.transform(item, context))
1485
- : this.transform(node.arg_names, context);
1486
- }
1487
- if (node.args !== undefined) {
1488
- result.args = Array.isArray(node.args)
1489
- ? node.args.map(item => this.transform(item, context))
1490
- : this.transform(node.args, context);
1491
- }
1492
- if (node.xmloption !== undefined) {
1493
- result.xmloption = node.xmloption;
1494
- }
1495
- if (node.type !== undefined) {
1496
- result.type = node.type;
1497
- }
1498
- if (node.typmod !== undefined) {
1499
- result.typmod = node.typmod;
1500
- }
1501
- if (node.location !== undefined) {
1502
- result.location = node.location;
1503
- }
1504
- return { XmlExpr: result };
1505
- }
1506
- RangeSubselect(node, context) {
1507
- const result = {};
1508
- if (node.lateral !== undefined) {
1509
- result.lateral = node.lateral;
1510
- }
1511
- if (node.subquery !== undefined) {
1512
- result.subquery = this.transform(node.subquery, context);
1513
- }
1514
- if (node.alias !== undefined) {
1515
- result.alias = this.transform(node.alias, context);
1516
- }
1517
- return { RangeSubselect: result };
1518
- }
1519
- SetToDefault(node, context) {
1520
- const result = {};
1521
- if (node.location !== undefined) {
1522
- result.location = node.location;
1523
- }
1524
- return { SetToDefault: result };
1525
- }
1526
- }