@pgsql/transform 18.1.1 → 18.3.0

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