pgsql-deparser 17.12.1 → 17.13.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.
- package/README.md +11 -9
- package/deparser.d.ts +0 -2
- package/deparser.js +179 -223
- package/esm/deparser.js +179 -223
- package/esm/kwlist.js +531 -0
- package/esm/utils/quote-utils.js +77 -46
- package/kwlist.d.ts +16 -0
- package/kwlist.js +535 -0
- package/package.json +11 -10
- package/utils/quote-utils.d.ts +23 -2
- package/utils/quote-utils.js +77 -46
package/esm/deparser.js
CHANGED
|
@@ -1188,12 +1188,12 @@ export class Deparser {
|
|
|
1188
1188
|
ResTarget(node, context) {
|
|
1189
1189
|
const output = [];
|
|
1190
1190
|
if (context.update && node.name) {
|
|
1191
|
-
output.push(QuoteUtils.
|
|
1191
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
1192
1192
|
// Handle indirection (array indexing, field access, etc.)
|
|
1193
1193
|
if (node.indirection && node.indirection.length > 0) {
|
|
1194
1194
|
const indirectionStrs = ListUtils.unwrapList(node.indirection).map(item => {
|
|
1195
1195
|
if (item.String) {
|
|
1196
|
-
return `.${QuoteUtils.
|
|
1196
|
+
return `.${QuoteUtils.quoteIdentifier(item.String.sval || item.String.str)}`;
|
|
1197
1197
|
}
|
|
1198
1198
|
return this.visit(item, context);
|
|
1199
1199
|
});
|
|
@@ -1205,12 +1205,12 @@ export class Deparser {
|
|
|
1205
1205
|
}
|
|
1206
1206
|
}
|
|
1207
1207
|
else if (context.insertColumns && node.name) {
|
|
1208
|
-
output.push(QuoteUtils.
|
|
1208
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
1209
1209
|
// Handle indirection for INSERT column lists (e.g., q.c1.r)
|
|
1210
1210
|
if (node.indirection && node.indirection.length > 0) {
|
|
1211
1211
|
const indirectionStrs = ListUtils.unwrapList(node.indirection).map(item => {
|
|
1212
1212
|
if (item.String) {
|
|
1213
|
-
return `.${QuoteUtils.
|
|
1213
|
+
return `.${QuoteUtils.quoteIdentifier(item.String.sval || item.String.str)}`;
|
|
1214
1214
|
}
|
|
1215
1215
|
return this.visit(item, context);
|
|
1216
1216
|
});
|
|
@@ -1223,7 +1223,7 @@ export class Deparser {
|
|
|
1223
1223
|
}
|
|
1224
1224
|
if (node.name) {
|
|
1225
1225
|
output.push('AS');
|
|
1226
|
-
output.push(QuoteUtils.
|
|
1226
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
1227
1227
|
}
|
|
1228
1228
|
}
|
|
1229
1229
|
return output.join(' ');
|
|
@@ -1237,7 +1237,7 @@ export class Deparser {
|
|
|
1237
1237
|
if (this.getNodeType(item) === 'ResTarget') {
|
|
1238
1238
|
const resTarget = this.getNodeData(item);
|
|
1239
1239
|
const val = resTarget.val ? this.visit(resTarget.val, context) : '';
|
|
1240
|
-
const alias = resTarget.name ? ` AS ${QuoteUtils.
|
|
1240
|
+
const alias = resTarget.name ? ` AS ${QuoteUtils.quoteIdentifier(resTarget.name)}` : '';
|
|
1241
1241
|
return val + alias;
|
|
1242
1242
|
}
|
|
1243
1243
|
else {
|
|
@@ -1674,7 +1674,7 @@ export class Deparser {
|
|
|
1674
1674
|
const fields = ListUtils.unwrapList(node.fields);
|
|
1675
1675
|
return fields.map(field => {
|
|
1676
1676
|
if (field.String) {
|
|
1677
|
-
return QuoteUtils.
|
|
1677
|
+
return QuoteUtils.quoteIdentifier(field.String.sval || field.String.str);
|
|
1678
1678
|
}
|
|
1679
1679
|
else if (field.A_Star) {
|
|
1680
1680
|
return '*';
|
|
@@ -1751,8 +1751,7 @@ export class Deparser {
|
|
|
1751
1751
|
}
|
|
1752
1752
|
return output.join(' ');
|
|
1753
1753
|
}
|
|
1754
|
-
|
|
1755
|
-
let result = mods(quotedTypeName, args);
|
|
1754
|
+
let result = mods(typeName, args);
|
|
1756
1755
|
if (node.arrayBounds && node.arrayBounds.length > 0) {
|
|
1757
1756
|
result += formatArrayBounds(node.arrayBounds);
|
|
1758
1757
|
}
|
|
@@ -1848,7 +1847,7 @@ export class Deparser {
|
|
|
1848
1847
|
return output.join(' ');
|
|
1849
1848
|
}
|
|
1850
1849
|
}
|
|
1851
|
-
const quotedNames = names.map((name) => QuoteUtils.
|
|
1850
|
+
const quotedNames = names.map((name) => QuoteUtils.quoteIdentifier(name));
|
|
1852
1851
|
let result = mods(quotedNames.join('.'), args);
|
|
1853
1852
|
if (node.arrayBounds && node.arrayBounds.length > 0) {
|
|
1854
1853
|
result += formatArrayBounds(node.arrayBounds);
|
|
@@ -1887,17 +1886,17 @@ export class Deparser {
|
|
|
1887
1886
|
}
|
|
1888
1887
|
let tableName = '';
|
|
1889
1888
|
if (node.catalogname) {
|
|
1890
|
-
tableName = QuoteUtils.
|
|
1889
|
+
tableName = QuoteUtils.quoteIdentifier(node.catalogname);
|
|
1891
1890
|
if (node.schemaname) {
|
|
1892
|
-
tableName += '.' + QuoteUtils.
|
|
1891
|
+
tableName += '.' + QuoteUtils.quoteIdentifier(node.schemaname);
|
|
1893
1892
|
}
|
|
1894
|
-
tableName += '.' + QuoteUtils.
|
|
1893
|
+
tableName += '.' + QuoteUtils.quoteIdentifier(node.relname);
|
|
1895
1894
|
}
|
|
1896
1895
|
else if (node.schemaname) {
|
|
1897
|
-
tableName = QuoteUtils.
|
|
1896
|
+
tableName = QuoteUtils.quoteQualifiedIdentifier(node.schemaname, node.relname);
|
|
1898
1897
|
}
|
|
1899
1898
|
else {
|
|
1900
|
-
tableName = QuoteUtils.
|
|
1899
|
+
tableName = QuoteUtils.quoteIdentifier(node.relname);
|
|
1901
1900
|
}
|
|
1902
1901
|
output.push(tableName);
|
|
1903
1902
|
if (node.alias) {
|
|
@@ -2123,7 +2122,7 @@ export class Deparser {
|
|
|
2123
2122
|
const indirection = ListUtils.unwrapList(node.indirection);
|
|
2124
2123
|
for (const subnode of indirection) {
|
|
2125
2124
|
if (subnode.String || subnode.A_Star) {
|
|
2126
|
-
const value = subnode.A_Star ? '*' : QuoteUtils.
|
|
2125
|
+
const value = subnode.A_Star ? '*' : QuoteUtils.quoteIdentifier(subnode.String.sval || subnode.String.str);
|
|
2127
2126
|
output.push(`.${value}`);
|
|
2128
2127
|
}
|
|
2129
2128
|
else {
|
|
@@ -2268,32 +2267,8 @@ export class Deparser {
|
|
|
2268
2267
|
}
|
|
2269
2268
|
return output.join(' ');
|
|
2270
2269
|
}
|
|
2271
|
-
static RESERVED_WORDS = new Set([
|
|
2272
|
-
'all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'both',
|
|
2273
|
-
'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'current_catalog',
|
|
2274
|
-
'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user',
|
|
2275
|
-
'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false',
|
|
2276
|
-
'fetch', 'for', 'foreign', 'from', 'grant', 'group', 'having', 'in', 'initially',
|
|
2277
|
-
'intersect', 'into', 'lateral', 'leading', 'limit', 'localtime', 'localtimestamp',
|
|
2278
|
-
'not', 'null', 'offset', 'on', 'only', 'or', 'order', 'placing', 'primary',
|
|
2279
|
-
'references', 'returning', 'select', 'session_user', 'some', 'symmetric', 'table',
|
|
2280
|
-
'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic',
|
|
2281
|
-
'when', 'where', 'window', 'with'
|
|
2282
|
-
]);
|
|
2283
|
-
static needsQuotes(value) {
|
|
2284
|
-
if (!value)
|
|
2285
|
-
return false;
|
|
2286
|
-
const needsQuotesRegex = /[a-z]+[\W\w]*[A-Z]+|[A-Z]+[\W\w]*[a-z]+|\W/;
|
|
2287
|
-
const isAllUppercase = /^[A-Z]+$/.test(value);
|
|
2288
|
-
return needsQuotesRegex.test(value) ||
|
|
2289
|
-
Deparser.RESERVED_WORDS.has(value.toLowerCase()) ||
|
|
2290
|
-
isAllUppercase;
|
|
2291
|
-
}
|
|
2292
2270
|
quoteIfNeeded(value) {
|
|
2293
|
-
|
|
2294
|
-
return `"${value}"`;
|
|
2295
|
-
}
|
|
2296
|
-
return value;
|
|
2271
|
+
return QuoteUtils.quoteIdentifier(value);
|
|
2297
2272
|
}
|
|
2298
2273
|
preserveOperatorDefElemCase(defName) {
|
|
2299
2274
|
const caseMap = {
|
|
@@ -2326,7 +2301,7 @@ export class Deparser {
|
|
|
2326
2301
|
return value; // Don't quote pure operator symbols like "=" or "-"
|
|
2327
2302
|
}
|
|
2328
2303
|
}
|
|
2329
|
-
return
|
|
2304
|
+
return QuoteUtils.quoteIdentifier(value);
|
|
2330
2305
|
}
|
|
2331
2306
|
Integer(node, context) {
|
|
2332
2307
|
return node.ival?.toString() || '0';
|
|
@@ -2503,7 +2478,7 @@ export class Deparser {
|
|
|
2503
2478
|
ColumnDef(node, context) {
|
|
2504
2479
|
const output = [];
|
|
2505
2480
|
if (node.colname) {
|
|
2506
|
-
output.push(QuoteUtils.
|
|
2481
|
+
output.push(QuoteUtils.quoteIdentifier(node.colname));
|
|
2507
2482
|
}
|
|
2508
2483
|
if (node.typeName) {
|
|
2509
2484
|
output.push(this.TypeName(node.typeName, context));
|
|
@@ -2544,7 +2519,7 @@ export class Deparser {
|
|
|
2544
2519
|
// Handle constraint name if present
|
|
2545
2520
|
if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN')) {
|
|
2546
2521
|
output.push('CONSTRAINT');
|
|
2547
|
-
output.push(QuoteUtils.
|
|
2522
|
+
output.push(QuoteUtils.quoteIdentifier(node.conname));
|
|
2548
2523
|
}
|
|
2549
2524
|
switch (node.contype) {
|
|
2550
2525
|
case 'CONSTR_NULL':
|
|
@@ -3441,7 +3416,7 @@ export class Deparser {
|
|
|
3441
3416
|
output.push('IF NOT EXISTS');
|
|
3442
3417
|
}
|
|
3443
3418
|
if (node.idxname) {
|
|
3444
|
-
output.push(QuoteUtils.
|
|
3419
|
+
output.push(QuoteUtils.quoteIdentifier(node.idxname));
|
|
3445
3420
|
}
|
|
3446
3421
|
output.push('ON');
|
|
3447
3422
|
if (node.relation) {
|
|
@@ -3475,14 +3450,14 @@ export class Deparser {
|
|
|
3475
3450
|
}
|
|
3476
3451
|
if (node.tableSpace) {
|
|
3477
3452
|
output.push('TABLESPACE');
|
|
3478
|
-
output.push(QuoteUtils.
|
|
3453
|
+
output.push(QuoteUtils.quoteIdentifier(node.tableSpace));
|
|
3479
3454
|
}
|
|
3480
3455
|
return output.join(' ');
|
|
3481
3456
|
}
|
|
3482
3457
|
IndexElem(node, context) {
|
|
3483
3458
|
const output = [];
|
|
3484
3459
|
if (node.name) {
|
|
3485
|
-
output.push(QuoteUtils.
|
|
3460
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
3486
3461
|
}
|
|
3487
3462
|
else if (node.expr) {
|
|
3488
3463
|
output.push(context.parens(this.visit(node.expr, context)));
|
|
@@ -3533,7 +3508,7 @@ export class Deparser {
|
|
|
3533
3508
|
PartitionElem(node, context) {
|
|
3534
3509
|
const output = [];
|
|
3535
3510
|
if (node.name) {
|
|
3536
|
-
output.push(QuoteUtils.
|
|
3511
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
3537
3512
|
}
|
|
3538
3513
|
else if (node.expr) {
|
|
3539
3514
|
output.push(context.parens(this.visit(node.expr, context)));
|
|
@@ -3783,19 +3758,19 @@ export class Deparser {
|
|
|
3783
3758
|
case 'TRANS_STMT_SAVEPOINT':
|
|
3784
3759
|
output.push('SAVEPOINT');
|
|
3785
3760
|
if (node.savepoint_name) {
|
|
3786
|
-
output.push(QuoteUtils.
|
|
3761
|
+
output.push(QuoteUtils.quoteIdentifier(node.savepoint_name));
|
|
3787
3762
|
}
|
|
3788
3763
|
break;
|
|
3789
3764
|
case 'TRANS_STMT_RELEASE':
|
|
3790
3765
|
output.push('RELEASE SAVEPOINT');
|
|
3791
3766
|
if (node.savepoint_name) {
|
|
3792
|
-
output.push(QuoteUtils.
|
|
3767
|
+
output.push(QuoteUtils.quoteIdentifier(node.savepoint_name));
|
|
3793
3768
|
}
|
|
3794
3769
|
break;
|
|
3795
3770
|
case 'TRANS_STMT_ROLLBACK_TO':
|
|
3796
3771
|
output.push('ROLLBACK TO');
|
|
3797
3772
|
if (node.savepoint_name) {
|
|
3798
|
-
output.push(QuoteUtils.
|
|
3773
|
+
output.push(QuoteUtils.quoteIdentifier(node.savepoint_name));
|
|
3799
3774
|
}
|
|
3800
3775
|
break;
|
|
3801
3776
|
case 'TRANS_STMT_PREPARE':
|
|
@@ -3892,16 +3867,16 @@ export class Deparser {
|
|
|
3892
3867
|
return this.visit(arg, context);
|
|
3893
3868
|
}).join(', ') : '';
|
|
3894
3869
|
// Handle args - always include TO clause if args exist (even if empty string)
|
|
3895
|
-
const paramName =
|
|
3870
|
+
const paramName = QuoteUtils.quoteIdentifier(node.name);
|
|
3896
3871
|
if (!node.args || node.args.length === 0) {
|
|
3897
3872
|
return `SET ${localPrefix}${paramName}`;
|
|
3898
3873
|
}
|
|
3899
3874
|
return `SET ${localPrefix}${paramName} TO ${args}`;
|
|
3900
3875
|
case 'VAR_SET_DEFAULT':
|
|
3901
|
-
const defaultParamName =
|
|
3876
|
+
const defaultParamName = QuoteUtils.quoteIdentifier(node.name);
|
|
3902
3877
|
return `SET ${defaultParamName} TO DEFAULT`;
|
|
3903
3878
|
case 'VAR_SET_CURRENT':
|
|
3904
|
-
const currentParamName =
|
|
3879
|
+
const currentParamName = QuoteUtils.quoteIdentifier(node.name);
|
|
3905
3880
|
return `SET ${currentParamName} FROM CURRENT`;
|
|
3906
3881
|
case 'VAR_SET_MULTI':
|
|
3907
3882
|
if (node.name === 'TRANSACTION' || node.name === 'SESSION CHARACTERISTICS') {
|
|
@@ -3975,7 +3950,7 @@ export class Deparser {
|
|
|
3975
3950
|
return `SET ${assignments}`;
|
|
3976
3951
|
}
|
|
3977
3952
|
case 'VAR_RESET':
|
|
3978
|
-
const resetParamName =
|
|
3953
|
+
const resetParamName = QuoteUtils.quoteIdentifier(node.name);
|
|
3979
3954
|
return `RESET ${resetParamName}`;
|
|
3980
3955
|
case 'VAR_RESET_ALL':
|
|
3981
3956
|
return 'RESET ALL';
|
|
@@ -4244,7 +4219,7 @@ export class Deparser {
|
|
|
4244
4219
|
if (objList && objList.List && objList.List.items) {
|
|
4245
4220
|
const items = objList.List.items.map((item) => {
|
|
4246
4221
|
if (item.String && item.String.sval) {
|
|
4247
|
-
return QuoteUtils.
|
|
4222
|
+
return QuoteUtils.quoteIdentifier(item.String.sval);
|
|
4248
4223
|
}
|
|
4249
4224
|
return this.visit(item, context);
|
|
4250
4225
|
}).filter((name) => name && name.trim());
|
|
@@ -4278,13 +4253,13 @@ export class Deparser {
|
|
|
4278
4253
|
if (items.length === 2) {
|
|
4279
4254
|
const accessMethod = items[0];
|
|
4280
4255
|
const objectName = items[1];
|
|
4281
|
-
return `${QuoteUtils.
|
|
4256
|
+
return `${QuoteUtils.quoteIdentifier(objectName)} USING ${accessMethod}`;
|
|
4282
4257
|
}
|
|
4283
4258
|
else if (items.length === 3) {
|
|
4284
4259
|
const accessMethod = items[0];
|
|
4285
4260
|
const schemaName = items[1];
|
|
4286
4261
|
const objectName = items[2];
|
|
4287
|
-
return `${QuoteUtils.
|
|
4262
|
+
return `${QuoteUtils.quoteQualifiedIdentifier(schemaName, objectName)} USING ${accessMethod}`;
|
|
4288
4263
|
}
|
|
4289
4264
|
return items.join('.');
|
|
4290
4265
|
}
|
|
@@ -4327,7 +4302,7 @@ export class Deparser {
|
|
|
4327
4302
|
if (objList && objList.List && objList.List.items) {
|
|
4328
4303
|
const items = objList.List.items.map((item) => {
|
|
4329
4304
|
if (item.String && item.String.sval) {
|
|
4330
|
-
return QuoteUtils.
|
|
4305
|
+
return QuoteUtils.quoteIdentifier(item.String.sval);
|
|
4331
4306
|
}
|
|
4332
4307
|
return this.visit(item, context);
|
|
4333
4308
|
}).filter((name) => name && name.trim());
|
|
@@ -4375,7 +4350,7 @@ export class Deparser {
|
|
|
4375
4350
|
PLAssignStmt(node, context) {
|
|
4376
4351
|
const output = [];
|
|
4377
4352
|
if (node.name) {
|
|
4378
|
-
let nameWithIndirection = QuoteUtils.
|
|
4353
|
+
let nameWithIndirection = QuoteUtils.quoteIdentifier(node.name);
|
|
4379
4354
|
if (node.indirection && node.indirection.length > 0) {
|
|
4380
4355
|
const indirectionStr = node.indirection
|
|
4381
4356
|
.map((ind) => this.visit(ind, context))
|
|
@@ -4524,7 +4499,7 @@ export class Deparser {
|
|
|
4524
4499
|
const parts = [];
|
|
4525
4500
|
const indentedParts = [];
|
|
4526
4501
|
if (colDefData.colname) {
|
|
4527
|
-
parts.push(QuoteUtils.
|
|
4502
|
+
parts.push(QuoteUtils.quoteIdentifier(colDefData.colname));
|
|
4528
4503
|
}
|
|
4529
4504
|
if (colDefData.typeName) {
|
|
4530
4505
|
parts.push(this.TypeName(colDefData.typeName, context));
|
|
@@ -4582,7 +4557,7 @@ export class Deparser {
|
|
|
4582
4557
|
else {
|
|
4583
4558
|
const parts = [];
|
|
4584
4559
|
if (colDefData.colname) {
|
|
4585
|
-
parts.push(QuoteUtils.
|
|
4560
|
+
parts.push(QuoteUtils.quoteIdentifier(colDefData.colname));
|
|
4586
4561
|
}
|
|
4587
4562
|
if (colDefData.typeName) {
|
|
4588
4563
|
parts.push(this.TypeName(colDefData.typeName, context));
|
|
@@ -4636,7 +4611,7 @@ export class Deparser {
|
|
|
4636
4611
|
}
|
|
4637
4612
|
}
|
|
4638
4613
|
if (node.name) {
|
|
4639
|
-
output.push(QuoteUtils.
|
|
4614
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4640
4615
|
}
|
|
4641
4616
|
if (node.behavior === 'DROP_CASCADE') {
|
|
4642
4617
|
output.push('CASCADE');
|
|
@@ -4653,7 +4628,7 @@ export class Deparser {
|
|
|
4653
4628
|
output.push('ALTER COLUMN');
|
|
4654
4629
|
}
|
|
4655
4630
|
if (node.name) {
|
|
4656
|
-
output.push(QuoteUtils.
|
|
4631
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4657
4632
|
}
|
|
4658
4633
|
output.push('TYPE');
|
|
4659
4634
|
if (node.def) {
|
|
@@ -4680,7 +4655,7 @@ export class Deparser {
|
|
|
4680
4655
|
case 'AT_SetTableSpace':
|
|
4681
4656
|
output.push('SET TABLESPACE');
|
|
4682
4657
|
if (node.name) {
|
|
4683
|
-
output.push(QuoteUtils.
|
|
4658
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4684
4659
|
}
|
|
4685
4660
|
break;
|
|
4686
4661
|
case 'AT_AddConstraint':
|
|
@@ -4698,7 +4673,7 @@ export class Deparser {
|
|
|
4698
4673
|
output.push('DROP CONSTRAINT');
|
|
4699
4674
|
}
|
|
4700
4675
|
if (node.name) {
|
|
4701
|
-
output.push(QuoteUtils.
|
|
4676
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4702
4677
|
}
|
|
4703
4678
|
if (node.behavior === 'DROP_CASCADE') {
|
|
4704
4679
|
output.push('CASCADE');
|
|
@@ -4736,7 +4711,7 @@ export class Deparser {
|
|
|
4736
4711
|
case 'AT_ColumnDefault':
|
|
4737
4712
|
output.push('ALTER COLUMN');
|
|
4738
4713
|
if (node.name) {
|
|
4739
|
-
output.push(QuoteUtils.
|
|
4714
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4740
4715
|
}
|
|
4741
4716
|
if (node.def) {
|
|
4742
4717
|
output.push('SET DEFAULT');
|
|
@@ -4749,7 +4724,7 @@ export class Deparser {
|
|
|
4749
4724
|
case 'AT_SetStorage':
|
|
4750
4725
|
output.push('ALTER COLUMN');
|
|
4751
4726
|
if (node.name) {
|
|
4752
|
-
output.push(QuoteUtils.
|
|
4727
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4753
4728
|
}
|
|
4754
4729
|
output.push('SET STORAGE');
|
|
4755
4730
|
if (node.def) {
|
|
@@ -4760,7 +4735,7 @@ export class Deparser {
|
|
|
4760
4735
|
case 'AT_ClusterOn':
|
|
4761
4736
|
output.push('CLUSTER ON');
|
|
4762
4737
|
if (node.name) {
|
|
4763
|
-
output.push(QuoteUtils.
|
|
4738
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4764
4739
|
}
|
|
4765
4740
|
break;
|
|
4766
4741
|
case 'AT_DropCluster':
|
|
@@ -4787,21 +4762,21 @@ export class Deparser {
|
|
|
4787
4762
|
case 'AT_SetNotNull':
|
|
4788
4763
|
output.push('ALTER COLUMN');
|
|
4789
4764
|
if (node.name) {
|
|
4790
|
-
output.push(QuoteUtils.
|
|
4765
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4791
4766
|
}
|
|
4792
4767
|
output.push('SET NOT NULL');
|
|
4793
4768
|
break;
|
|
4794
4769
|
case 'AT_DropNotNull':
|
|
4795
4770
|
output.push('ALTER COLUMN');
|
|
4796
4771
|
if (node.name) {
|
|
4797
|
-
output.push(QuoteUtils.
|
|
4772
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4798
4773
|
}
|
|
4799
4774
|
output.push('DROP NOT NULL');
|
|
4800
4775
|
break;
|
|
4801
4776
|
case 'AT_SetStatistics':
|
|
4802
4777
|
output.push('ALTER COLUMN');
|
|
4803
4778
|
if (node.name) {
|
|
4804
|
-
output.push(QuoteUtils.
|
|
4779
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4805
4780
|
}
|
|
4806
4781
|
else if (node.num !== undefined && node.num !== null) {
|
|
4807
4782
|
output.push(node.num.toString());
|
|
@@ -4814,7 +4789,7 @@ export class Deparser {
|
|
|
4814
4789
|
case 'AT_SetOptions':
|
|
4815
4790
|
output.push('ALTER COLUMN');
|
|
4816
4791
|
if (node.name) {
|
|
4817
|
-
output.push(QuoteUtils.
|
|
4792
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4818
4793
|
}
|
|
4819
4794
|
output.push('SET');
|
|
4820
4795
|
if (node.def) {
|
|
@@ -4831,7 +4806,7 @@ export class Deparser {
|
|
|
4831
4806
|
case 'AT_ResetOptions':
|
|
4832
4807
|
output.push('ALTER COLUMN');
|
|
4833
4808
|
if (node.name) {
|
|
4834
|
-
output.push(QuoteUtils.
|
|
4809
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4835
4810
|
}
|
|
4836
4811
|
output.push('RESET');
|
|
4837
4812
|
if (node.def) {
|
|
@@ -4848,7 +4823,7 @@ export class Deparser {
|
|
|
4848
4823
|
case 'AT_SetCompression':
|
|
4849
4824
|
output.push('ALTER COLUMN');
|
|
4850
4825
|
if (node.name) {
|
|
4851
|
-
output.push(QuoteUtils.
|
|
4826
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4852
4827
|
}
|
|
4853
4828
|
output.push('SET COMPRESSION');
|
|
4854
4829
|
if (node.def) {
|
|
@@ -4858,31 +4833,31 @@ export class Deparser {
|
|
|
4858
4833
|
case 'AT_ValidateConstraint':
|
|
4859
4834
|
output.push('VALIDATE CONSTRAINT');
|
|
4860
4835
|
if (node.name) {
|
|
4861
|
-
output.push(QuoteUtils.
|
|
4836
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4862
4837
|
}
|
|
4863
4838
|
break;
|
|
4864
4839
|
case 'AT_EnableTrig':
|
|
4865
4840
|
output.push('ENABLE TRIGGER');
|
|
4866
4841
|
if (node.name) {
|
|
4867
|
-
output.push(QuoteUtils.
|
|
4842
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4868
4843
|
}
|
|
4869
4844
|
break;
|
|
4870
4845
|
case 'AT_EnableAlwaysTrig':
|
|
4871
4846
|
output.push('ENABLE ALWAYS TRIGGER');
|
|
4872
4847
|
if (node.name) {
|
|
4873
|
-
output.push(QuoteUtils.
|
|
4848
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4874
4849
|
}
|
|
4875
4850
|
break;
|
|
4876
4851
|
case 'AT_EnableReplicaTrig':
|
|
4877
4852
|
output.push('ENABLE REPLICA TRIGGER');
|
|
4878
4853
|
if (node.name) {
|
|
4879
|
-
output.push(QuoteUtils.
|
|
4854
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4880
4855
|
}
|
|
4881
4856
|
break;
|
|
4882
4857
|
case 'AT_DisableTrig':
|
|
4883
4858
|
output.push('DISABLE TRIGGER');
|
|
4884
4859
|
if (node.name) {
|
|
4885
|
-
output.push(QuoteUtils.
|
|
4860
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4886
4861
|
}
|
|
4887
4862
|
break;
|
|
4888
4863
|
case 'AT_EnableTrigAll':
|
|
@@ -4900,31 +4875,31 @@ export class Deparser {
|
|
|
4900
4875
|
case 'AT_EnableRule':
|
|
4901
4876
|
output.push('ENABLE RULE');
|
|
4902
4877
|
if (node.name) {
|
|
4903
|
-
output.push(QuoteUtils.
|
|
4878
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4904
4879
|
}
|
|
4905
4880
|
break;
|
|
4906
4881
|
case 'AT_EnableAlwaysRule':
|
|
4907
4882
|
output.push('ENABLE ALWAYS RULE');
|
|
4908
4883
|
if (node.name) {
|
|
4909
|
-
output.push(QuoteUtils.
|
|
4884
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4910
4885
|
}
|
|
4911
4886
|
break;
|
|
4912
4887
|
case 'AT_EnableReplicaRule':
|
|
4913
4888
|
output.push('ENABLE REPLICA RULE');
|
|
4914
4889
|
if (node.name) {
|
|
4915
|
-
output.push(QuoteUtils.
|
|
4890
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4916
4891
|
}
|
|
4917
4892
|
break;
|
|
4918
4893
|
case 'AT_DisableRule':
|
|
4919
4894
|
output.push('DISABLE RULE');
|
|
4920
4895
|
if (node.name) {
|
|
4921
|
-
output.push(QuoteUtils.
|
|
4896
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4922
4897
|
}
|
|
4923
4898
|
break;
|
|
4924
4899
|
case 'AT_SetAccessMethod':
|
|
4925
4900
|
output.push('SET ACCESS METHOD');
|
|
4926
4901
|
if (node.name) {
|
|
4927
|
-
output.push(QuoteUtils.
|
|
4902
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4928
4903
|
}
|
|
4929
4904
|
else {
|
|
4930
4905
|
// Handle DEFAULT access method case
|
|
@@ -4978,7 +4953,7 @@ export class Deparser {
|
|
|
4978
4953
|
case 'AT_CookedColumnDefault':
|
|
4979
4954
|
output.push('ALTER COLUMN');
|
|
4980
4955
|
if (node.name) {
|
|
4981
|
-
output.push(QuoteUtils.
|
|
4956
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4982
4957
|
}
|
|
4983
4958
|
if (node.def) {
|
|
4984
4959
|
output.push('SET DEFAULT');
|
|
@@ -4991,7 +4966,7 @@ export class Deparser {
|
|
|
4991
4966
|
case 'AT_SetExpression':
|
|
4992
4967
|
output.push('ALTER COLUMN');
|
|
4993
4968
|
if (node.name) {
|
|
4994
|
-
output.push(QuoteUtils.
|
|
4969
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
4995
4970
|
}
|
|
4996
4971
|
output.push('SET EXPRESSION');
|
|
4997
4972
|
if (node.def) {
|
|
@@ -5001,14 +4976,14 @@ export class Deparser {
|
|
|
5001
4976
|
case 'AT_DropExpression':
|
|
5002
4977
|
output.push('ALTER COLUMN');
|
|
5003
4978
|
if (node.name) {
|
|
5004
|
-
output.push(QuoteUtils.
|
|
4979
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
5005
4980
|
}
|
|
5006
4981
|
output.push('DROP EXPRESSION');
|
|
5007
4982
|
break;
|
|
5008
4983
|
case 'AT_CheckNotNull':
|
|
5009
4984
|
output.push('ALTER COLUMN');
|
|
5010
4985
|
if (node.name) {
|
|
5011
|
-
output.push(QuoteUtils.
|
|
4986
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
5012
4987
|
}
|
|
5013
4988
|
output.push('SET NOT NULL');
|
|
5014
4989
|
break;
|
|
@@ -5041,7 +5016,7 @@ export class Deparser {
|
|
|
5041
5016
|
if (node.def && this.getNodeType(node.def) === 'Constraint') {
|
|
5042
5017
|
const constraintData = this.getNodeData(node.def);
|
|
5043
5018
|
if (constraintData.conname) {
|
|
5044
|
-
output.push(QuoteUtils.
|
|
5019
|
+
output.push(QuoteUtils.quoteIdentifier(constraintData.conname));
|
|
5045
5020
|
if (constraintData.deferrable !== undefined) {
|
|
5046
5021
|
output.push(constraintData.deferrable ? 'DEFERRABLE' : 'NOT DEFERRABLE');
|
|
5047
5022
|
}
|
|
@@ -5051,7 +5026,7 @@ export class Deparser {
|
|
|
5051
5026
|
}
|
|
5052
5027
|
}
|
|
5053
5028
|
else if (node.name) {
|
|
5054
|
-
output.push(QuoteUtils.
|
|
5029
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
5055
5030
|
if (node.def) {
|
|
5056
5031
|
output.push(this.visit(node.def, context));
|
|
5057
5032
|
}
|
|
@@ -5072,7 +5047,7 @@ export class Deparser {
|
|
|
5072
5047
|
case 'AT_AlterColumnGenericOptions':
|
|
5073
5048
|
output.push('ALTER COLUMN');
|
|
5074
5049
|
if (node.name) {
|
|
5075
|
-
output.push(QuoteUtils.
|
|
5050
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
5076
5051
|
}
|
|
5077
5052
|
output.push('OPTIONS');
|
|
5078
5053
|
if (node.def) {
|
|
@@ -5126,7 +5101,7 @@ export class Deparser {
|
|
|
5126
5101
|
case 'AT_AddIdentity':
|
|
5127
5102
|
output.push('ALTER COLUMN');
|
|
5128
5103
|
if (node.name) {
|
|
5129
|
-
output.push(QuoteUtils.
|
|
5104
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
5130
5105
|
}
|
|
5131
5106
|
output.push('ADD');
|
|
5132
5107
|
if (node.def) {
|
|
@@ -5136,7 +5111,7 @@ export class Deparser {
|
|
|
5136
5111
|
case 'AT_SetIdentity':
|
|
5137
5112
|
output.push('ALTER COLUMN');
|
|
5138
5113
|
if (node.name) {
|
|
5139
|
-
output.push(QuoteUtils.
|
|
5114
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
5140
5115
|
}
|
|
5141
5116
|
output.push('SET');
|
|
5142
5117
|
if (node.def) {
|
|
@@ -5146,7 +5121,7 @@ export class Deparser {
|
|
|
5146
5121
|
case 'AT_DropIdentity':
|
|
5147
5122
|
output.push('ALTER COLUMN');
|
|
5148
5123
|
if (node.name) {
|
|
5149
|
-
output.push(QuoteUtils.
|
|
5124
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
5150
5125
|
}
|
|
5151
5126
|
output.push('DROP IDENTITY');
|
|
5152
5127
|
if (node.behavior === 'DROP_CASCADE') {
|
|
@@ -5285,7 +5260,7 @@ export class Deparser {
|
|
|
5285
5260
|
}
|
|
5286
5261
|
}
|
|
5287
5262
|
if (node.name) {
|
|
5288
|
-
output.push(QuoteUtils.
|
|
5263
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
5289
5264
|
}
|
|
5290
5265
|
if (node.argType) {
|
|
5291
5266
|
output.push(this.TypeName(node.argType, context));
|
|
@@ -5357,7 +5332,7 @@ export class Deparser {
|
|
|
5357
5332
|
output.push('ROLE');
|
|
5358
5333
|
}
|
|
5359
5334
|
if (node.role) {
|
|
5360
|
-
const roleName =
|
|
5335
|
+
const roleName = QuoteUtils.quoteIdentifier(node.role);
|
|
5361
5336
|
output.push(roleName);
|
|
5362
5337
|
}
|
|
5363
5338
|
if (node.options) {
|
|
@@ -5399,7 +5374,7 @@ export class Deparser {
|
|
|
5399
5374
|
if (context.parentNodeTypes.includes('DefineStmt') &&
|
|
5400
5375
|
['hashes', 'merges'].includes(node.defname.toLowerCase()) && !node.arg) {
|
|
5401
5376
|
if (node.defname !== node.defname.toLowerCase() && node.defname !== node.defname.toUpperCase()) {
|
|
5402
|
-
return
|
|
5377
|
+
return QuoteUtils.quoteIdentifier(node.defname);
|
|
5403
5378
|
}
|
|
5404
5379
|
return node.defname.charAt(0).toUpperCase() + node.defname.slice(1).toLowerCase();
|
|
5405
5380
|
}
|
|
@@ -5421,9 +5396,7 @@ export class Deparser {
|
|
|
5421
5396
|
const finalValue = typeof argValue === 'string' && !argValue.startsWith("'")
|
|
5422
5397
|
? `'${argValue}'`
|
|
5423
5398
|
: argValue;
|
|
5424
|
-
const quotedDefname =
|
|
5425
|
-
? `"${node.defname}"`
|
|
5426
|
-
: node.defname;
|
|
5399
|
+
const quotedDefname = QuoteUtils.quoteIdentifier(node.defname);
|
|
5427
5400
|
if (node.defaction === 'DEFELEM_ADD') {
|
|
5428
5401
|
return `ADD ${quotedDefname} ${finalValue}`;
|
|
5429
5402
|
}
|
|
@@ -5447,9 +5420,7 @@ export class Deparser {
|
|
|
5447
5420
|
else if (node.defaction === 'DEFELEM_SET') {
|
|
5448
5421
|
return `SET ${node.defname} ${quotedValue}`;
|
|
5449
5422
|
}
|
|
5450
|
-
const quotedDefname =
|
|
5451
|
-
? `"${node.defname}"`
|
|
5452
|
-
: node.defname;
|
|
5423
|
+
const quotedDefname = QuoteUtils.quoteIdentifier(node.defname);
|
|
5453
5424
|
return `${quotedDefname} ${quotedValue}`;
|
|
5454
5425
|
}
|
|
5455
5426
|
else if (node.defaction === 'DEFELEM_DROP') {
|
|
@@ -5509,9 +5480,7 @@ export class Deparser {
|
|
|
5509
5480
|
const quotedValue = typeof argValue === 'string'
|
|
5510
5481
|
? QuoteUtils.escape(argValue)
|
|
5511
5482
|
: argValue;
|
|
5512
|
-
const quotedDefname =
|
|
5513
|
-
? `"${node.defname}"`
|
|
5514
|
-
: node.defname;
|
|
5483
|
+
const quotedDefname = QuoteUtils.quoteIdentifier(node.defname);
|
|
5515
5484
|
return `${quotedDefname} ${quotedValue}`;
|
|
5516
5485
|
}
|
|
5517
5486
|
if (context.parentNodeTypes.includes('CreateRoleStmt') || context.parentNodeTypes.includes('AlterRoleStmt')) {
|
|
@@ -5586,10 +5555,7 @@ export class Deparser {
|
|
|
5586
5555
|
if (this.getNodeType(item) === 'String') {
|
|
5587
5556
|
// Check if this identifier needs quotes to preserve case
|
|
5588
5557
|
const value = itemData.sval;
|
|
5589
|
-
|
|
5590
|
-
return `"${value}"`;
|
|
5591
|
-
}
|
|
5592
|
-
return value;
|
|
5558
|
+
return QuoteUtils.quoteIdentifier(value);
|
|
5593
5559
|
}
|
|
5594
5560
|
return this.visit(item, context);
|
|
5595
5561
|
});
|
|
@@ -5837,13 +5803,13 @@ export class Deparser {
|
|
|
5837
5803
|
// Handle boolean flags (no arguments) - preserve quoted case
|
|
5838
5804
|
if (['hashes', 'merges'].includes(node.defname.toLowerCase())) {
|
|
5839
5805
|
if (node.defname !== node.defname.toLowerCase() && node.defname !== node.defname.toUpperCase()) {
|
|
5840
|
-
return
|
|
5806
|
+
return QuoteUtils.quoteIdentifier(node.defname);
|
|
5841
5807
|
}
|
|
5842
5808
|
return preservedName.toUpperCase();
|
|
5843
5809
|
}
|
|
5844
5810
|
// Handle CREATE AGGREGATE quoted identifiers - preserve quotes when needed
|
|
5845
|
-
|
|
5846
|
-
|
|
5811
|
+
const quotedDefname = QuoteUtils.quoteIdentifier(node.defname);
|
|
5812
|
+
if (quotedDefname !== node.defname) {
|
|
5847
5813
|
if (node.arg) {
|
|
5848
5814
|
if (this.getNodeType(node.arg) === 'String') {
|
|
5849
5815
|
const stringData = this.getNodeData(node.arg);
|
|
@@ -5903,7 +5869,7 @@ export class Deparser {
|
|
|
5903
5869
|
if (context.parentNodeTypes.includes('DefineStmt') && !node.arg) {
|
|
5904
5870
|
// Check if the original defname appears to be quoted (mixed case that's not all upper/lower)
|
|
5905
5871
|
if (node.defname !== node.defname.toLowerCase() && node.defname !== node.defname.toUpperCase()) {
|
|
5906
|
-
return
|
|
5872
|
+
return QuoteUtils.quoteIdentifier(node.defname);
|
|
5907
5873
|
}
|
|
5908
5874
|
}
|
|
5909
5875
|
return node.defname.toUpperCase();
|
|
@@ -6087,7 +6053,7 @@ export class Deparser {
|
|
|
6087
6053
|
case 'REPLICA_IDENTITY_INDEX':
|
|
6088
6054
|
output.push('USING', 'INDEX');
|
|
6089
6055
|
if (node.name) {
|
|
6090
|
-
output.push(QuoteUtils.
|
|
6056
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
6091
6057
|
}
|
|
6092
6058
|
break;
|
|
6093
6059
|
default:
|
|
@@ -6146,7 +6112,7 @@ export class Deparser {
|
|
|
6146
6112
|
output.push('IF', 'EXISTS');
|
|
6147
6113
|
}
|
|
6148
6114
|
if (node.name) {
|
|
6149
|
-
output.push(QuoteUtils.
|
|
6115
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
6150
6116
|
}
|
|
6151
6117
|
if (node.behavior === 'DROP_CASCADE') {
|
|
6152
6118
|
output.push('CASCADE');
|
|
@@ -6155,7 +6121,7 @@ export class Deparser {
|
|
|
6155
6121
|
case 'AT_ValidateConstraint':
|
|
6156
6122
|
output.push('VALIDATE', 'CONSTRAINT');
|
|
6157
6123
|
if (node.name) {
|
|
6158
|
-
output.push(QuoteUtils.
|
|
6124
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
6159
6125
|
}
|
|
6160
6126
|
break;
|
|
6161
6127
|
case 'C':
|
|
@@ -6172,7 +6138,7 @@ export class Deparser {
|
|
|
6172
6138
|
output.push('IF', 'EXISTS');
|
|
6173
6139
|
}
|
|
6174
6140
|
if (node.name) {
|
|
6175
|
-
output.push(QuoteUtils.
|
|
6141
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
6176
6142
|
}
|
|
6177
6143
|
if (node.behavior === 'DROP_CASCADE') {
|
|
6178
6144
|
output.push('CASCADE');
|
|
@@ -6181,7 +6147,7 @@ export class Deparser {
|
|
|
6181
6147
|
case 'V':
|
|
6182
6148
|
output.push('VALIDATE', 'CONSTRAINT');
|
|
6183
6149
|
if (node.name) {
|
|
6184
|
-
output.push(QuoteUtils.
|
|
6150
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
6185
6151
|
}
|
|
6186
6152
|
break;
|
|
6187
6153
|
case 'O':
|
|
@@ -6570,7 +6536,7 @@ export class Deparser {
|
|
|
6570
6536
|
const output = [];
|
|
6571
6537
|
const initialParts = ['CREATE', 'POLICY'];
|
|
6572
6538
|
if (node.policy_name) {
|
|
6573
|
-
initialParts.push(QuoteUtils.
|
|
6539
|
+
initialParts.push(QuoteUtils.quoteIdentifier(node.policy_name));
|
|
6574
6540
|
}
|
|
6575
6541
|
output.push(initialParts.join(' '));
|
|
6576
6542
|
// Add ON clause on new line in pretty mode
|
|
@@ -6647,7 +6613,7 @@ export class Deparser {
|
|
|
6647
6613
|
AlterPolicyStmt(node, context) {
|
|
6648
6614
|
const output = ['ALTER', 'POLICY'];
|
|
6649
6615
|
if (node.policy_name) {
|
|
6650
|
-
output.push(QuoteUtils.
|
|
6616
|
+
output.push(QuoteUtils.quoteIdentifier(node.policy_name));
|
|
6651
6617
|
}
|
|
6652
6618
|
if (node.table) {
|
|
6653
6619
|
output.push('ON');
|
|
@@ -6683,7 +6649,7 @@ export class Deparser {
|
|
|
6683
6649
|
}
|
|
6684
6650
|
output.push('SERVER');
|
|
6685
6651
|
if (node.servername) {
|
|
6686
|
-
output.push(
|
|
6652
|
+
output.push(QuoteUtils.quoteIdentifier(node.servername));
|
|
6687
6653
|
}
|
|
6688
6654
|
if (node.options && node.options.length > 0) {
|
|
6689
6655
|
output.push('OPTIONS');
|
|
@@ -6731,7 +6697,7 @@ export class Deparser {
|
|
|
6731
6697
|
CreatePublicationStmt(node, context) {
|
|
6732
6698
|
const output = ['CREATE', 'PUBLICATION'];
|
|
6733
6699
|
if (node.pubname) {
|
|
6734
|
-
output.push(
|
|
6700
|
+
output.push(QuoteUtils.quoteIdentifier(node.pubname));
|
|
6735
6701
|
}
|
|
6736
6702
|
if (node.pubobjects && node.pubobjects.length > 0) {
|
|
6737
6703
|
output.push('FOR', 'TABLE');
|
|
@@ -6751,7 +6717,7 @@ export class Deparser {
|
|
|
6751
6717
|
CreateSubscriptionStmt(node, context) {
|
|
6752
6718
|
const output = ['CREATE', 'SUBSCRIPTION'];
|
|
6753
6719
|
if (node.subname) {
|
|
6754
|
-
output.push(
|
|
6720
|
+
output.push(QuoteUtils.quoteIdentifier(node.subname));
|
|
6755
6721
|
}
|
|
6756
6722
|
output.push('CONNECTION');
|
|
6757
6723
|
if (node.conninfo) {
|
|
@@ -6772,7 +6738,7 @@ export class Deparser {
|
|
|
6772
6738
|
AlterPublicationStmt(node, context) {
|
|
6773
6739
|
const output = ['ALTER', 'PUBLICATION'];
|
|
6774
6740
|
if (node.pubname) {
|
|
6775
|
-
output.push(
|
|
6741
|
+
output.push(QuoteUtils.quoteIdentifier(node.pubname));
|
|
6776
6742
|
}
|
|
6777
6743
|
if (node.action) {
|
|
6778
6744
|
switch (node.action) {
|
|
@@ -6807,7 +6773,7 @@ export class Deparser {
|
|
|
6807
6773
|
AlterSubscriptionStmt(node, context) {
|
|
6808
6774
|
const output = ['ALTER', 'SUBSCRIPTION'];
|
|
6809
6775
|
if (node.subname) {
|
|
6810
|
-
output.push(
|
|
6776
|
+
output.push(QuoteUtils.quoteIdentifier(node.subname));
|
|
6811
6777
|
}
|
|
6812
6778
|
if (node.kind) {
|
|
6813
6779
|
switch (node.kind) {
|
|
@@ -6853,7 +6819,7 @@ export class Deparser {
|
|
|
6853
6819
|
output.push('IF EXISTS');
|
|
6854
6820
|
}
|
|
6855
6821
|
if (node.subname) {
|
|
6856
|
-
output.push(
|
|
6822
|
+
output.push(QuoteUtils.quoteIdentifier(node.subname));
|
|
6857
6823
|
}
|
|
6858
6824
|
if (node.behavior) {
|
|
6859
6825
|
switch (node.behavior) {
|
|
@@ -7098,7 +7064,7 @@ export class Deparser {
|
|
|
7098
7064
|
ClosePortalStmt(node, context) {
|
|
7099
7065
|
const output = ['CLOSE'];
|
|
7100
7066
|
if (node.portalname) {
|
|
7101
|
-
output.push(QuoteUtils.
|
|
7067
|
+
output.push(QuoteUtils.quoteIdentifier(node.portalname));
|
|
7102
7068
|
}
|
|
7103
7069
|
else {
|
|
7104
7070
|
output.push('ALL');
|
|
@@ -7156,7 +7122,7 @@ export class Deparser {
|
|
|
7156
7122
|
output.push('ALL');
|
|
7157
7123
|
}
|
|
7158
7124
|
if (node.portalname) {
|
|
7159
|
-
output.push(QuoteUtils.
|
|
7125
|
+
output.push(QuoteUtils.quoteIdentifier(node.portalname));
|
|
7160
7126
|
}
|
|
7161
7127
|
return output.join(' ');
|
|
7162
7128
|
}
|
|
@@ -7226,7 +7192,7 @@ export class Deparser {
|
|
|
7226
7192
|
AlterFdwStmt(node, context) {
|
|
7227
7193
|
const output = ['ALTER', 'FOREIGN', 'DATA', 'WRAPPER'];
|
|
7228
7194
|
if (node.fdwname) {
|
|
7229
|
-
output.push(QuoteUtils.
|
|
7195
|
+
output.push(QuoteUtils.quoteIdentifier(node.fdwname));
|
|
7230
7196
|
}
|
|
7231
7197
|
if (node.func_options && node.func_options.length > 0) {
|
|
7232
7198
|
const fdwContext = context.spawn('AlterFdwStmt');
|
|
@@ -7247,7 +7213,7 @@ export class Deparser {
|
|
|
7247
7213
|
output.push('IF', 'NOT', 'EXISTS');
|
|
7248
7214
|
}
|
|
7249
7215
|
if (node.servername) {
|
|
7250
|
-
output.push(QuoteUtils.
|
|
7216
|
+
output.push(QuoteUtils.quoteIdentifier(node.servername));
|
|
7251
7217
|
}
|
|
7252
7218
|
if (node.servertype) {
|
|
7253
7219
|
output.push('TYPE', QuoteUtils.escape(node.servertype));
|
|
@@ -7256,7 +7222,7 @@ export class Deparser {
|
|
|
7256
7222
|
output.push('VERSION', QuoteUtils.escape(node.version));
|
|
7257
7223
|
}
|
|
7258
7224
|
if (node.fdwname) {
|
|
7259
|
-
output.push('FOREIGN', 'DATA', 'WRAPPER', QuoteUtils.
|
|
7225
|
+
output.push('FOREIGN', 'DATA', 'WRAPPER', QuoteUtils.quoteIdentifier(node.fdwname));
|
|
7260
7226
|
}
|
|
7261
7227
|
if (node.options && node.options.length > 0) {
|
|
7262
7228
|
output.push('OPTIONS');
|
|
@@ -7271,7 +7237,7 @@ export class Deparser {
|
|
|
7271
7237
|
AlterForeignServerStmt(node, context) {
|
|
7272
7238
|
const output = ['ALTER', 'SERVER'];
|
|
7273
7239
|
if (node.servername) {
|
|
7274
|
-
output.push(QuoteUtils.
|
|
7240
|
+
output.push(QuoteUtils.quoteIdentifier(node.servername));
|
|
7275
7241
|
}
|
|
7276
7242
|
if (node.version) {
|
|
7277
7243
|
output.push('VERSION', QuoteUtils.escape(node.version));
|
|
@@ -7296,7 +7262,7 @@ export class Deparser {
|
|
|
7296
7262
|
}
|
|
7297
7263
|
output.push('SERVER');
|
|
7298
7264
|
if (node.servername) {
|
|
7299
|
-
output.push(QuoteUtils.
|
|
7265
|
+
output.push(QuoteUtils.quoteIdentifier(node.servername));
|
|
7300
7266
|
}
|
|
7301
7267
|
if (node.options && node.options.length > 0) {
|
|
7302
7268
|
output.push('OPTIONS');
|
|
@@ -7320,14 +7286,14 @@ export class Deparser {
|
|
|
7320
7286
|
}
|
|
7321
7287
|
output.push('SERVER');
|
|
7322
7288
|
if (node.servername) {
|
|
7323
|
-
output.push(QuoteUtils.
|
|
7289
|
+
output.push(QuoteUtils.quoteIdentifier(node.servername));
|
|
7324
7290
|
}
|
|
7325
7291
|
return output.join(' ');
|
|
7326
7292
|
}
|
|
7327
7293
|
ImportForeignSchemaStmt(node, context) {
|
|
7328
7294
|
const output = ['IMPORT', 'FOREIGN', 'SCHEMA'];
|
|
7329
7295
|
if (node.remote_schema) {
|
|
7330
|
-
output.push(QuoteUtils.
|
|
7296
|
+
output.push(QuoteUtils.quoteIdentifier(node.remote_schema));
|
|
7331
7297
|
}
|
|
7332
7298
|
if (node.list_type) {
|
|
7333
7299
|
switch (node.list_type) {
|
|
@@ -7353,11 +7319,11 @@ export class Deparser {
|
|
|
7353
7319
|
}
|
|
7354
7320
|
output.push('FROM', 'SERVER');
|
|
7355
7321
|
if (node.server_name) {
|
|
7356
|
-
output.push(QuoteUtils.
|
|
7322
|
+
output.push(QuoteUtils.quoteIdentifier(node.server_name));
|
|
7357
7323
|
}
|
|
7358
7324
|
output.push('INTO');
|
|
7359
7325
|
if (node.local_schema) {
|
|
7360
|
-
output.push(QuoteUtils.
|
|
7326
|
+
output.push(QuoteUtils.quoteIdentifier(node.local_schema));
|
|
7361
7327
|
}
|
|
7362
7328
|
if (node.options && node.options.length > 0) {
|
|
7363
7329
|
const importSchemaContext = context.spawn('ImportForeignSchemaStmt');
|
|
@@ -7371,7 +7337,7 @@ export class Deparser {
|
|
|
7371
7337
|
if (node.relation) {
|
|
7372
7338
|
output.push(this.RangeVar(node.relation, context));
|
|
7373
7339
|
if (node.indexname) {
|
|
7374
|
-
output.push('USING',
|
|
7340
|
+
output.push('USING', QuoteUtils.quoteIdentifier(node.indexname));
|
|
7375
7341
|
}
|
|
7376
7342
|
}
|
|
7377
7343
|
if (node.params && node.params.length > 0) {
|
|
@@ -7435,7 +7401,7 @@ export class Deparser {
|
|
|
7435
7401
|
output.push(this.RangeVar(node.relation, context));
|
|
7436
7402
|
}
|
|
7437
7403
|
if (node.name) {
|
|
7438
|
-
output.push(
|
|
7404
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
7439
7405
|
}
|
|
7440
7406
|
return output.join(' ');
|
|
7441
7407
|
}
|
|
@@ -7475,7 +7441,7 @@ export class Deparser {
|
|
|
7475
7441
|
if (!node.dbname) {
|
|
7476
7442
|
throw new Error('CreatedbStmt requires dbname');
|
|
7477
7443
|
}
|
|
7478
|
-
output.push(
|
|
7444
|
+
output.push(QuoteUtils.quoteIdentifier(node.dbname));
|
|
7479
7445
|
if (node.options && node.options.length > 0) {
|
|
7480
7446
|
const options = ListUtils.unwrapList(node.options)
|
|
7481
7447
|
.map(option => this.visit(option, context))
|
|
@@ -7492,7 +7458,7 @@ export class Deparser {
|
|
|
7492
7458
|
if (!node.dbname) {
|
|
7493
7459
|
throw new Error('DropdbStmt requires dbname');
|
|
7494
7460
|
}
|
|
7495
|
-
output.push(
|
|
7461
|
+
output.push(QuoteUtils.quoteIdentifier(node.dbname));
|
|
7496
7462
|
if (node.options && node.options.length > 0) {
|
|
7497
7463
|
const options = ListUtils.unwrapList(node.options)
|
|
7498
7464
|
.map(option => this.visit(option, context))
|
|
@@ -7590,7 +7556,7 @@ export class Deparser {
|
|
|
7590
7556
|
case 'OBJECT_POLICY':
|
|
7591
7557
|
output.push('POLICY');
|
|
7592
7558
|
if (node.subname) {
|
|
7593
|
-
output.push(QuoteUtils.
|
|
7559
|
+
output.push(QuoteUtils.quoteIdentifier(node.subname));
|
|
7594
7560
|
}
|
|
7595
7561
|
break;
|
|
7596
7562
|
case 'OBJECT_PUBLICATION':
|
|
@@ -7648,7 +7614,7 @@ export class Deparser {
|
|
|
7648
7614
|
}
|
|
7649
7615
|
// Handle OBJECT_RULE special case: rule_name ON table_name format
|
|
7650
7616
|
if (node.renameType === 'OBJECT_RULE' && node.subname && node.relation) {
|
|
7651
|
-
output.push(QuoteUtils.
|
|
7617
|
+
output.push(QuoteUtils.quoteIdentifier(node.subname));
|
|
7652
7618
|
output.push('ON');
|
|
7653
7619
|
output.push(this.RangeVar(node.relation, context));
|
|
7654
7620
|
}
|
|
@@ -7667,7 +7633,7 @@ export class Deparser {
|
|
|
7667
7633
|
if (items.length === 2) {
|
|
7668
7634
|
const accessMethod = items[0].String?.sval || '';
|
|
7669
7635
|
const objectName = items[1].String?.sval || '';
|
|
7670
|
-
output.push(`${QuoteUtils.
|
|
7636
|
+
output.push(`${QuoteUtils.quoteIdentifier(objectName)} USING ${accessMethod}`);
|
|
7671
7637
|
}
|
|
7672
7638
|
else {
|
|
7673
7639
|
output.push(this.visit(node.object, context));
|
|
@@ -7688,19 +7654,19 @@ export class Deparser {
|
|
|
7688
7654
|
}
|
|
7689
7655
|
}
|
|
7690
7656
|
if (node.renameType === 'OBJECT_COLUMN' && node.subname) {
|
|
7691
|
-
output.push('RENAME COLUMN',
|
|
7657
|
+
output.push('RENAME COLUMN', QuoteUtils.quoteIdentifier(node.subname), 'TO');
|
|
7692
7658
|
}
|
|
7693
7659
|
else if (node.renameType === 'OBJECT_DOMCONSTRAINT' && node.subname) {
|
|
7694
|
-
output.push('RENAME CONSTRAINT',
|
|
7660
|
+
output.push('RENAME CONSTRAINT', QuoteUtils.quoteIdentifier(node.subname), 'TO');
|
|
7695
7661
|
}
|
|
7696
7662
|
else if (node.renameType === 'OBJECT_TABCONSTRAINT' && node.subname) {
|
|
7697
|
-
output.push('RENAME CONSTRAINT',
|
|
7663
|
+
output.push('RENAME CONSTRAINT', QuoteUtils.quoteIdentifier(node.subname), 'TO');
|
|
7698
7664
|
}
|
|
7699
7665
|
else if (node.renameType === 'OBJECT_ATTRIBUTE' && node.subname) {
|
|
7700
|
-
output.push('RENAME ATTRIBUTE',
|
|
7666
|
+
output.push('RENAME ATTRIBUTE', QuoteUtils.quoteIdentifier(node.subname), 'TO');
|
|
7701
7667
|
}
|
|
7702
7668
|
else if (node.renameType === 'OBJECT_ROLE' && node.subname) {
|
|
7703
|
-
output.push(
|
|
7669
|
+
output.push(QuoteUtils.quoteIdentifier(node.subname), 'RENAME TO');
|
|
7704
7670
|
}
|
|
7705
7671
|
else if (node.renameType === 'OBJECT_SCHEMA' && node.subname) {
|
|
7706
7672
|
output.push(this.quoteIfNeeded(node.subname), 'RENAME TO');
|
|
@@ -7714,7 +7680,7 @@ export class Deparser {
|
|
|
7714
7680
|
if (!node.newname) {
|
|
7715
7681
|
throw new Error('RenameStmt requires newname');
|
|
7716
7682
|
}
|
|
7717
|
-
output.push(QuoteUtils.
|
|
7683
|
+
output.push(QuoteUtils.quoteIdentifier(node.newname));
|
|
7718
7684
|
// Handle CASCADE/RESTRICT behavior for RENAME operations
|
|
7719
7685
|
if (node.behavior === 'DROP_CASCADE') {
|
|
7720
7686
|
output.push('CASCADE');
|
|
@@ -7737,7 +7703,7 @@ export class Deparser {
|
|
|
7737
7703
|
if (items.length === 2) {
|
|
7738
7704
|
const accessMethod = items[0].String?.sval || '';
|
|
7739
7705
|
const objectName = items[1].String?.sval || '';
|
|
7740
|
-
output.push(`${QuoteUtils.
|
|
7706
|
+
output.push(`${QuoteUtils.quoteIdentifier(objectName)} USING ${accessMethod}`);
|
|
7741
7707
|
}
|
|
7742
7708
|
else {
|
|
7743
7709
|
output.push(this.visit(node.object, context));
|
|
@@ -8007,7 +7973,7 @@ export class Deparser {
|
|
|
8007
7973
|
SecLabelStmt(node, context) {
|
|
8008
7974
|
const output = ['SECURITY LABEL'];
|
|
8009
7975
|
if (node.provider) {
|
|
8010
|
-
output.push('FOR',
|
|
7976
|
+
output.push('FOR', QuoteUtils.quoteIdentifier(node.provider));
|
|
8011
7977
|
}
|
|
8012
7978
|
output.push('ON');
|
|
8013
7979
|
if (node.objtype) {
|
|
@@ -8160,7 +8126,7 @@ export class Deparser {
|
|
|
8160
8126
|
}
|
|
8161
8127
|
output.push('LANGUAGE');
|
|
8162
8128
|
if (node.plname) {
|
|
8163
|
-
output.push(QuoteUtils.
|
|
8129
|
+
output.push(QuoteUtils.quoteIdentifier(node.plname));
|
|
8164
8130
|
}
|
|
8165
8131
|
if (node.plhandler && node.plhandler.length > 0) {
|
|
8166
8132
|
output.push('HANDLER');
|
|
@@ -8196,7 +8162,7 @@ export class Deparser {
|
|
|
8196
8162
|
}
|
|
8197
8163
|
output.push('LANGUAGE');
|
|
8198
8164
|
if (node.lang) {
|
|
8199
|
-
output.push(QuoteUtils.
|
|
8165
|
+
output.push(QuoteUtils.quoteIdentifier(node.lang));
|
|
8200
8166
|
}
|
|
8201
8167
|
output.push('(');
|
|
8202
8168
|
const transforms = [];
|
|
@@ -8224,7 +8190,7 @@ export class Deparser {
|
|
|
8224
8190
|
}
|
|
8225
8191
|
output.push('TRIGGER');
|
|
8226
8192
|
if (node.trigname) {
|
|
8227
|
-
output.push(QuoteUtils.
|
|
8193
|
+
output.push(QuoteUtils.quoteIdentifier(node.trigname));
|
|
8228
8194
|
}
|
|
8229
8195
|
if (context.isPretty()) {
|
|
8230
8196
|
const components = [];
|
|
@@ -8388,14 +8354,14 @@ export class Deparser {
|
|
|
8388
8354
|
output.push('OLD TABLE AS');
|
|
8389
8355
|
}
|
|
8390
8356
|
if (node.name) {
|
|
8391
|
-
output.push(QuoteUtils.
|
|
8357
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
8392
8358
|
}
|
|
8393
8359
|
return output.join(' ');
|
|
8394
8360
|
}
|
|
8395
8361
|
CreateEventTrigStmt(node, context) {
|
|
8396
8362
|
const output = ['CREATE EVENT TRIGGER'];
|
|
8397
8363
|
if (node.trigname) {
|
|
8398
|
-
output.push(QuoteUtils.
|
|
8364
|
+
output.push(QuoteUtils.quoteIdentifier(node.trigname));
|
|
8399
8365
|
}
|
|
8400
8366
|
output.push('ON');
|
|
8401
8367
|
if (node.eventname) {
|
|
@@ -8421,7 +8387,7 @@ export class Deparser {
|
|
|
8421
8387
|
AlterEventTrigStmt(node, context) {
|
|
8422
8388
|
const output = ['ALTER EVENT TRIGGER'];
|
|
8423
8389
|
if (node.trigname) {
|
|
8424
|
-
output.push(QuoteUtils.
|
|
8390
|
+
output.push(QuoteUtils.quoteIdentifier(node.trigname));
|
|
8425
8391
|
}
|
|
8426
8392
|
if (node.tgenabled) {
|
|
8427
8393
|
switch (node.tgenabled) {
|
|
@@ -8556,11 +8522,11 @@ export class Deparser {
|
|
|
8556
8522
|
}
|
|
8557
8523
|
output.push('ALL', 'IN', 'TABLESPACE');
|
|
8558
8524
|
if (node.orig_tablespacename) {
|
|
8559
|
-
output.push(QuoteUtils.
|
|
8525
|
+
output.push(QuoteUtils.quoteIdentifier(node.orig_tablespacename));
|
|
8560
8526
|
}
|
|
8561
8527
|
output.push('SET', 'TABLESPACE');
|
|
8562
8528
|
if (node.new_tablespacename) {
|
|
8563
|
-
output.push(QuoteUtils.
|
|
8529
|
+
output.push(QuoteUtils.quoteIdentifier(node.new_tablespacename));
|
|
8564
8530
|
}
|
|
8565
8531
|
if (node.nowait) {
|
|
8566
8532
|
output.push('NOWAIT');
|
|
@@ -8584,10 +8550,10 @@ export class Deparser {
|
|
|
8584
8550
|
const sequenceName = [];
|
|
8585
8551
|
const seq = node.sequence;
|
|
8586
8552
|
if (seq.schemaname) {
|
|
8587
|
-
sequenceName.push(QuoteUtils.
|
|
8553
|
+
sequenceName.push(QuoteUtils.quoteIdentifier(seq.schemaname));
|
|
8588
8554
|
}
|
|
8589
8555
|
if (seq.relname) {
|
|
8590
|
-
sequenceName.push(QuoteUtils.
|
|
8556
|
+
sequenceName.push(QuoteUtils.quoteIdentifier(seq.relname));
|
|
8591
8557
|
}
|
|
8592
8558
|
output.push(sequenceName.join('.'));
|
|
8593
8559
|
}
|
|
@@ -8621,10 +8587,10 @@ export class Deparser {
|
|
|
8621
8587
|
const sequenceName = [];
|
|
8622
8588
|
const seq = node.sequence;
|
|
8623
8589
|
if (seq.schemaname) {
|
|
8624
|
-
sequenceName.push(QuoteUtils.
|
|
8590
|
+
sequenceName.push(QuoteUtils.quoteIdentifier(seq.schemaname));
|
|
8625
8591
|
}
|
|
8626
8592
|
if (seq.relname) {
|
|
8627
|
-
sequenceName.push(QuoteUtils.
|
|
8593
|
+
sequenceName.push(QuoteUtils.quoteIdentifier(seq.relname));
|
|
8628
8594
|
}
|
|
8629
8595
|
output.push(sequenceName.join('.'));
|
|
8630
8596
|
}
|
|
@@ -8971,7 +8937,7 @@ export class Deparser {
|
|
|
8971
8937
|
}
|
|
8972
8938
|
aliasname(node, context) {
|
|
8973
8939
|
if (typeof node === 'string') {
|
|
8974
|
-
return QuoteUtils.
|
|
8940
|
+
return QuoteUtils.quoteIdentifier(node);
|
|
8975
8941
|
}
|
|
8976
8942
|
return this.visit(node, context);
|
|
8977
8943
|
}
|
|
@@ -9003,13 +8969,8 @@ export class Deparser {
|
|
|
9003
8969
|
const defName = defElem.defname;
|
|
9004
8970
|
const defValue = defElem.arg;
|
|
9005
8971
|
if (defName && defValue) {
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
preservedDefName = `"${defName}"`;
|
|
9009
|
-
}
|
|
9010
|
-
else {
|
|
9011
|
-
preservedDefName = this.preserveOperatorDefElemCase(defName);
|
|
9012
|
-
}
|
|
8972
|
+
const quotedDefName = QuoteUtils.quoteIdentifier(defName);
|
|
8973
|
+
const preservedDefName = quotedDefName !== defName ? quotedDefName : this.preserveOperatorDefElemCase(defName);
|
|
9013
8974
|
if ((defName.toLowerCase() === 'commutator' || defName.toLowerCase() === 'negator') && defValue.List) {
|
|
9014
8975
|
const listItems = ListUtils.unwrapList(defValue.List.items);
|
|
9015
8976
|
if (listItems.length === 1 && listItems[0].String) {
|
|
@@ -9025,7 +8986,7 @@ export class Deparser {
|
|
|
9025
8986
|
else if (defName && !defValue) {
|
|
9026
8987
|
// Handle boolean flags like HASHES, MERGES - preserve original case
|
|
9027
8988
|
if (defName === 'Hashes' || defName === 'Merges') {
|
|
9028
|
-
return
|
|
8989
|
+
return QuoteUtils.quoteIdentifier(defName);
|
|
9029
8990
|
}
|
|
9030
8991
|
return this.preserveOperatorDefElemCase(defName).toUpperCase();
|
|
9031
8992
|
}
|
|
@@ -9164,13 +9125,8 @@ export class Deparser {
|
|
|
9164
9125
|
const defName = defElem.defname;
|
|
9165
9126
|
const defValue = defElem.arg;
|
|
9166
9127
|
if (defName && defValue) {
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
preservedDefName = `"${defName}"`;
|
|
9170
|
-
}
|
|
9171
|
-
else {
|
|
9172
|
-
preservedDefName = defName;
|
|
9173
|
-
}
|
|
9128
|
+
const quotedDefName = QuoteUtils.quoteIdentifier(defName);
|
|
9129
|
+
const preservedDefName = quotedDefName !== defName ? quotedDefName : defName;
|
|
9174
9130
|
// Handle String arguments with single quotes for string literals
|
|
9175
9131
|
if (defValue.String) {
|
|
9176
9132
|
return `${preservedDefName} = '${defValue.String.sval}'`;
|
|
@@ -9325,7 +9281,7 @@ export class Deparser {
|
|
|
9325
9281
|
AlterDatabaseStmt(node, context) {
|
|
9326
9282
|
const output = ['ALTER', 'DATABASE'];
|
|
9327
9283
|
if (node.dbname) {
|
|
9328
|
-
output.push(QuoteUtils.
|
|
9284
|
+
output.push(QuoteUtils.quoteIdentifier(node.dbname));
|
|
9329
9285
|
}
|
|
9330
9286
|
if (node.options && node.options.length > 0) {
|
|
9331
9287
|
const options = ListUtils.unwrapList(node.options).map(opt => this.visit(opt, context));
|
|
@@ -9336,7 +9292,7 @@ export class Deparser {
|
|
|
9336
9292
|
AlterDatabaseRefreshCollStmt(node, context) {
|
|
9337
9293
|
const output = ['ALTER', 'DATABASE'];
|
|
9338
9294
|
if (node.dbname) {
|
|
9339
|
-
output.push(QuoteUtils.
|
|
9295
|
+
output.push(QuoteUtils.quoteIdentifier(node.dbname));
|
|
9340
9296
|
}
|
|
9341
9297
|
output.push('REFRESH', 'COLLATION', 'VERSION');
|
|
9342
9298
|
return output.join(' ');
|
|
@@ -9344,7 +9300,7 @@ export class Deparser {
|
|
|
9344
9300
|
AlterDatabaseSetStmt(node, context) {
|
|
9345
9301
|
const output = ['ALTER', 'DATABASE'];
|
|
9346
9302
|
if (node.dbname) {
|
|
9347
|
-
output.push(QuoteUtils.
|
|
9303
|
+
output.push(QuoteUtils.quoteIdentifier(node.dbname));
|
|
9348
9304
|
}
|
|
9349
9305
|
if (node.setstmt) {
|
|
9350
9306
|
const setClause = this.VariableSetStmt(node.setstmt, context);
|
|
@@ -9355,7 +9311,7 @@ export class Deparser {
|
|
|
9355
9311
|
DeclareCursorStmt(node, context) {
|
|
9356
9312
|
const output = ['DECLARE'];
|
|
9357
9313
|
if (node.portalname) {
|
|
9358
|
-
output.push(QuoteUtils.
|
|
9314
|
+
output.push(QuoteUtils.quoteIdentifier(node.portalname));
|
|
9359
9315
|
}
|
|
9360
9316
|
// Handle cursor options before CURSOR keyword
|
|
9361
9317
|
const cursorOptions = [];
|
|
@@ -9397,7 +9353,7 @@ export class Deparser {
|
|
|
9397
9353
|
else if (node.pubobjtype === 'PUBLICATIONOBJ_TABLES_IN_SCHEMA') {
|
|
9398
9354
|
output.push('TABLES IN SCHEMA');
|
|
9399
9355
|
if (node.name) {
|
|
9400
|
-
output.push(QuoteUtils.
|
|
9356
|
+
output.push(QuoteUtils.quoteIdentifier(node.name));
|
|
9401
9357
|
}
|
|
9402
9358
|
}
|
|
9403
9359
|
else if (node.pubobjtype === 'PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA') {
|
|
@@ -9423,7 +9379,7 @@ export class Deparser {
|
|
|
9423
9379
|
CreateAmStmt(node, context) {
|
|
9424
9380
|
const output = ['CREATE', 'ACCESS', 'METHOD'];
|
|
9425
9381
|
if (node.amname) {
|
|
9426
|
-
output.push(QuoteUtils.
|
|
9382
|
+
output.push(QuoteUtils.quoteIdentifier(node.amname));
|
|
9427
9383
|
}
|
|
9428
9384
|
output.push('TYPE');
|
|
9429
9385
|
switch (node.amtype) {
|
|
@@ -9483,7 +9439,7 @@ export class Deparser {
|
|
|
9483
9439
|
}
|
|
9484
9440
|
}
|
|
9485
9441
|
if (node.tableSpaceName) {
|
|
9486
|
-
output.push('TABLESPACE', QuoteUtils.
|
|
9442
|
+
output.push('TABLESPACE', QuoteUtils.quoteIdentifier(node.tableSpaceName));
|
|
9487
9443
|
}
|
|
9488
9444
|
return output.join(' ');
|
|
9489
9445
|
}
|
|
@@ -9641,7 +9597,7 @@ export class Deparser {
|
|
|
9641
9597
|
RangeTableFuncCol(node, context) {
|
|
9642
9598
|
const output = [];
|
|
9643
9599
|
if (node.colname) {
|
|
9644
|
-
output.push(QuoteUtils.
|
|
9600
|
+
output.push(QuoteUtils.quoteIdentifier(node.colname));
|
|
9645
9601
|
}
|
|
9646
9602
|
if (node.for_ordinality) {
|
|
9647
9603
|
output.push('FOR ORDINALITY');
|
|
@@ -9787,10 +9743,10 @@ export class Deparser {
|
|
|
9787
9743
|
if (node.op === 'IS_XMLPI') {
|
|
9788
9744
|
if (node.name && node.args && node.args.length > 0) {
|
|
9789
9745
|
const argStrs = ListUtils.unwrapList(node.args).map(arg => this.visit(arg, context));
|
|
9790
|
-
return `xmlpi(name ${QuoteUtils.
|
|
9746
|
+
return `xmlpi(name ${QuoteUtils.quoteIdentifier(node.name)}, ${argStrs.join(', ')})`;
|
|
9791
9747
|
}
|
|
9792
9748
|
else if (node.name) {
|
|
9793
|
-
return `xmlpi(name ${QuoteUtils.
|
|
9749
|
+
return `xmlpi(name ${QuoteUtils.quoteIdentifier(node.name)})`;
|
|
9794
9750
|
}
|
|
9795
9751
|
else {
|
|
9796
9752
|
return 'XMLPI()';
|
|
@@ -9805,7 +9761,7 @@ export class Deparser {
|
|
|
9805
9761
|
output.push('XMLELEMENT');
|
|
9806
9762
|
const elementParts = [];
|
|
9807
9763
|
if (node.name) {
|
|
9808
|
-
elementParts.push(`NAME ${QuoteUtils.
|
|
9764
|
+
elementParts.push(`NAME ${QuoteUtils.quoteIdentifier(node.name)}`);
|
|
9809
9765
|
}
|
|
9810
9766
|
if (node.named_args && node.named_args.length > 0) {
|
|
9811
9767
|
const namedArgStrs = ListUtils.unwrapList(node.named_args).map(arg => this.visit(arg, context));
|
|
@@ -9905,7 +9861,7 @@ export class Deparser {
|
|
|
9905
9861
|
// Handle name and args for operations that don't have special handling
|
|
9906
9862
|
if (node.op !== 'IS_XMLELEMENT' && node.op !== 'IS_XMLPARSE' && node.op !== 'IS_XMLROOT' && node.op !== 'IS_DOCUMENT') {
|
|
9907
9863
|
if (node.name) {
|
|
9908
|
-
const quotedName = QuoteUtils.
|
|
9864
|
+
const quotedName = QuoteUtils.quoteIdentifier(node.name);
|
|
9909
9865
|
output.push(`NAME ${quotedName}`);
|
|
9910
9866
|
}
|
|
9911
9867
|
if (node.args && node.args.length > 0) {
|
|
@@ -9926,26 +9882,26 @@ export class Deparser {
|
|
|
9926
9882
|
}
|
|
9927
9883
|
schemaname(node, context) {
|
|
9928
9884
|
if (typeof node === 'string') {
|
|
9929
|
-
return QuoteUtils.
|
|
9885
|
+
return QuoteUtils.quoteIdentifier(node);
|
|
9930
9886
|
}
|
|
9931
9887
|
if (node && node.String && node.String.sval) {
|
|
9932
|
-
return QuoteUtils.
|
|
9888
|
+
return QuoteUtils.quoteIdentifier(node.String.sval);
|
|
9933
9889
|
}
|
|
9934
9890
|
// Handle other node types without recursion
|
|
9935
9891
|
if (node && typeof node === 'object') {
|
|
9936
9892
|
if (node.sval !== undefined) {
|
|
9937
|
-
return QuoteUtils.
|
|
9893
|
+
return QuoteUtils.quoteIdentifier(node.sval);
|
|
9938
9894
|
}
|
|
9939
9895
|
// Handle List nodes that might contain schema names
|
|
9940
9896
|
if (node.List && Array.isArray(node.List.items)) {
|
|
9941
9897
|
const items = node.List.items;
|
|
9942
9898
|
if (items.length > 0 && items[0].String && items[0].String.sval) {
|
|
9943
|
-
return QuoteUtils.
|
|
9899
|
+
return QuoteUtils.quoteIdentifier(items[0].String.sval);
|
|
9944
9900
|
}
|
|
9945
9901
|
}
|
|
9946
9902
|
// For other complex nodes, try to extract string value without recursion
|
|
9947
9903
|
if (node.val !== undefined) {
|
|
9948
|
-
return QuoteUtils.
|
|
9904
|
+
return QuoteUtils.quoteIdentifier(node.val);
|
|
9949
9905
|
}
|
|
9950
9906
|
return '';
|
|
9951
9907
|
}
|
|
@@ -10008,7 +9964,7 @@ export class Deparser {
|
|
|
10008
9964
|
}
|
|
10009
9965
|
output.push('RULE');
|
|
10010
9966
|
if (node.rulename) {
|
|
10011
|
-
output.push(QuoteUtils.
|
|
9967
|
+
output.push(QuoteUtils.quoteIdentifier(node.rulename));
|
|
10012
9968
|
}
|
|
10013
9969
|
output.push('AS ON');
|
|
10014
9970
|
if (node.event) {
|
|
@@ -10075,42 +10031,42 @@ export class Deparser {
|
|
|
10075
10031
|
}
|
|
10076
10032
|
relname(node, context) {
|
|
10077
10033
|
if (typeof node === 'string') {
|
|
10078
|
-
return QuoteUtils.
|
|
10034
|
+
return QuoteUtils.quoteIdentifier(node);
|
|
10079
10035
|
}
|
|
10080
10036
|
if (node && node.String && node.String.sval) {
|
|
10081
|
-
return QuoteUtils.
|
|
10037
|
+
return QuoteUtils.quoteIdentifier(node.String.sval);
|
|
10082
10038
|
}
|
|
10083
10039
|
if (node && typeof node === 'object' && node.relname) {
|
|
10084
|
-
return QuoteUtils.
|
|
10040
|
+
return QuoteUtils.quoteIdentifier(node.relname);
|
|
10085
10041
|
}
|
|
10086
10042
|
return this.visit(node, context);
|
|
10087
10043
|
}
|
|
10088
10044
|
rel(node, context) {
|
|
10089
10045
|
if (typeof node === 'string') {
|
|
10090
|
-
return QuoteUtils.
|
|
10046
|
+
return QuoteUtils.quoteIdentifier(node);
|
|
10091
10047
|
}
|
|
10092
10048
|
if (node && node.String && node.String.sval) {
|
|
10093
|
-
return QuoteUtils.
|
|
10049
|
+
return QuoteUtils.quoteIdentifier(node.String.sval);
|
|
10094
10050
|
}
|
|
10095
10051
|
if (node && node.RangeVar) {
|
|
10096
10052
|
return this.RangeVar(node.RangeVar, context);
|
|
10097
10053
|
}
|
|
10098
10054
|
if (node && typeof node === 'object' && node.relname) {
|
|
10099
|
-
return QuoteUtils.
|
|
10055
|
+
return QuoteUtils.quoteIdentifier(node.relname);
|
|
10100
10056
|
}
|
|
10101
10057
|
return this.visit(node, context);
|
|
10102
10058
|
}
|
|
10103
10059
|
objname(node, context) {
|
|
10104
10060
|
if (typeof node === 'string') {
|
|
10105
|
-
return QuoteUtils.
|
|
10061
|
+
return QuoteUtils.quoteIdentifier(node);
|
|
10106
10062
|
}
|
|
10107
10063
|
if (node && node.String && node.String.sval) {
|
|
10108
|
-
return QuoteUtils.
|
|
10064
|
+
return QuoteUtils.quoteIdentifier(node.String.sval);
|
|
10109
10065
|
}
|
|
10110
10066
|
if (Array.isArray(node)) {
|
|
10111
10067
|
const parts = node.map(part => {
|
|
10112
10068
|
if (part && part.String && part.String.sval) {
|
|
10113
|
-
return QuoteUtils.
|
|
10069
|
+
return QuoteUtils.quoteIdentifier(part.String.sval);
|
|
10114
10070
|
}
|
|
10115
10071
|
return this.visit(part, context);
|
|
10116
10072
|
});
|
|
@@ -10181,7 +10137,7 @@ export class Deparser {
|
|
|
10181
10137
|
CurrentOfExpr(node, context) {
|
|
10182
10138
|
const output = ['CURRENT OF'];
|
|
10183
10139
|
if (node.cursor_name) {
|
|
10184
|
-
output.push(QuoteUtils.
|
|
10140
|
+
output.push(QuoteUtils.quoteIdentifier(node.cursor_name));
|
|
10185
10141
|
}
|
|
10186
10142
|
if (node.cursor_param > 0) {
|
|
10187
10143
|
output.push(`$${node.cursor_param}`);
|
|
@@ -10264,7 +10220,7 @@ export class Deparser {
|
|
|
10264
10220
|
if (items.length === 2) {
|
|
10265
10221
|
const schemaName = items[0].String?.sval || '';
|
|
10266
10222
|
const domainName = items[1].String?.sval || '';
|
|
10267
|
-
output.push(
|
|
10223
|
+
output.push(QuoteUtils.quoteQualifiedIdentifier(schemaName, domainName));
|
|
10268
10224
|
}
|
|
10269
10225
|
else {
|
|
10270
10226
|
output.push(this.visit(node.object, context));
|
|
@@ -10276,7 +10232,7 @@ export class Deparser {
|
|
|
10276
10232
|
if (items.length === 2) {
|
|
10277
10233
|
const schemaName = items[0].String?.sval || '';
|
|
10278
10234
|
const typeName = items[1].String?.sval || '';
|
|
10279
|
-
output.push(
|
|
10235
|
+
output.push(QuoteUtils.quoteQualifiedIdentifier(schemaName, typeName));
|
|
10280
10236
|
}
|
|
10281
10237
|
else {
|
|
10282
10238
|
output.push(this.visit(node.object, context));
|
|
@@ -10288,7 +10244,7 @@ export class Deparser {
|
|
|
10288
10244
|
if (items.length === 2) {
|
|
10289
10245
|
const schemaName = items[0].String?.sval || '';
|
|
10290
10246
|
const conversionName = items[1].String?.sval || '';
|
|
10291
|
-
output.push(
|
|
10247
|
+
output.push(QuoteUtils.quoteQualifiedIdentifier(schemaName, conversionName));
|
|
10292
10248
|
}
|
|
10293
10249
|
else {
|
|
10294
10250
|
output.push(this.visit(node.object, context));
|
|
@@ -10300,7 +10256,7 @@ export class Deparser {
|
|
|
10300
10256
|
if (items.length === 2) {
|
|
10301
10257
|
const schemaName = items[0].String?.sval || '';
|
|
10302
10258
|
const parserName = items[1].String?.sval || '';
|
|
10303
|
-
output.push(
|
|
10259
|
+
output.push(QuoteUtils.quoteQualifiedIdentifier(schemaName, parserName));
|
|
10304
10260
|
}
|
|
10305
10261
|
else {
|
|
10306
10262
|
output.push(this.visit(node.object, context));
|
|
@@ -10312,7 +10268,7 @@ export class Deparser {
|
|
|
10312
10268
|
if (items.length === 2) {
|
|
10313
10269
|
const schemaName = items[0].String?.sval || '';
|
|
10314
10270
|
const configName = items[1].String?.sval || '';
|
|
10315
|
-
output.push(
|
|
10271
|
+
output.push(QuoteUtils.quoteQualifiedIdentifier(schemaName, configName));
|
|
10316
10272
|
}
|
|
10317
10273
|
else {
|
|
10318
10274
|
output.push(this.visit(node.object, context));
|
|
@@ -10324,7 +10280,7 @@ export class Deparser {
|
|
|
10324
10280
|
if (items.length === 2) {
|
|
10325
10281
|
const schemaName = items[0].String?.sval || '';
|
|
10326
10282
|
const templateName = items[1].String?.sval || '';
|
|
10327
|
-
output.push(
|
|
10283
|
+
output.push(QuoteUtils.quoteQualifiedIdentifier(schemaName, templateName));
|
|
10328
10284
|
}
|
|
10329
10285
|
else {
|
|
10330
10286
|
output.push(this.visit(node.object, context));
|
|
@@ -10336,7 +10292,7 @@ export class Deparser {
|
|
|
10336
10292
|
if (items.length === 2) {
|
|
10337
10293
|
const schemaName = items[0].String?.sval || '';
|
|
10338
10294
|
const dictionaryName = items[1].String?.sval || '';
|
|
10339
|
-
output.push(
|
|
10295
|
+
output.push(QuoteUtils.quoteQualifiedIdentifier(schemaName, dictionaryName));
|
|
10340
10296
|
}
|
|
10341
10297
|
else {
|
|
10342
10298
|
output.push(this.visit(node.object, context));
|
|
@@ -10348,13 +10304,13 @@ export class Deparser {
|
|
|
10348
10304
|
if (items.length === 2) {
|
|
10349
10305
|
const accessMethod = items[0].String?.sval || '';
|
|
10350
10306
|
const opClassName = items[1].String?.sval || '';
|
|
10351
|
-
output.push(`${QuoteUtils.
|
|
10307
|
+
output.push(`${QuoteUtils.quoteIdentifier(opClassName)} USING ${accessMethod}`);
|
|
10352
10308
|
}
|
|
10353
10309
|
else if (items.length === 3) {
|
|
10354
10310
|
const accessMethod = items[0].String?.sval || '';
|
|
10355
10311
|
const schemaName = items[1].String?.sval || '';
|
|
10356
10312
|
const opClassName = items[2].String?.sval || '';
|
|
10357
|
-
output.push(`${QuoteUtils.
|
|
10313
|
+
output.push(`${QuoteUtils.quoteQualifiedIdentifier(schemaName, opClassName)} USING ${accessMethod}`);
|
|
10358
10314
|
}
|
|
10359
10315
|
else {
|
|
10360
10316
|
output.push(this.visit(node.object, context));
|
|
@@ -10366,13 +10322,13 @@ export class Deparser {
|
|
|
10366
10322
|
if (items.length === 2) {
|
|
10367
10323
|
const accessMethod = items[0].String?.sval || '';
|
|
10368
10324
|
const opFamilyName = items[1].String?.sval || '';
|
|
10369
|
-
output.push(`${QuoteUtils.
|
|
10325
|
+
output.push(`${QuoteUtils.quoteIdentifier(opFamilyName)} USING ${accessMethod}`);
|
|
10370
10326
|
}
|
|
10371
10327
|
else if (items.length === 3) {
|
|
10372
10328
|
const accessMethod = items[0].String?.sval || '';
|
|
10373
10329
|
const schemaName = items[1].String?.sval || '';
|
|
10374
10330
|
const opFamilyName = items[2].String?.sval || '';
|
|
10375
|
-
output.push(`${QuoteUtils.
|
|
10331
|
+
output.push(`${QuoteUtils.quoteQualifiedIdentifier(schemaName, opFamilyName)} USING ${accessMethod}`);
|
|
10376
10332
|
}
|
|
10377
10333
|
else {
|
|
10378
10334
|
output.push(this.visit(node.object, context));
|
|
@@ -10384,7 +10340,7 @@ export class Deparser {
|
|
|
10384
10340
|
}
|
|
10385
10341
|
output.push('SET SCHEMA');
|
|
10386
10342
|
if (node.newschema) {
|
|
10387
|
-
output.push(QuoteUtils.
|
|
10343
|
+
output.push(QuoteUtils.quoteIdentifier(node.newschema));
|
|
10388
10344
|
}
|
|
10389
10345
|
return output.join(' ');
|
|
10390
10346
|
}
|
|
@@ -10453,7 +10409,7 @@ export class Deparser {
|
|
|
10453
10409
|
}
|
|
10454
10410
|
if (node.servername) {
|
|
10455
10411
|
output.push('SERVER');
|
|
10456
|
-
output.push(QuoteUtils.
|
|
10412
|
+
output.push(QuoteUtils.quoteIdentifier(node.servername));
|
|
10457
10413
|
}
|
|
10458
10414
|
if (node.options && node.options.length > 0) {
|
|
10459
10415
|
const foreignTableContext = context.spawn('CreateForeignTableStmt');
|