pgsql-deparser 17.12.2 → 17.14.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/deparser.js CHANGED
@@ -1191,12 +1191,12 @@ class Deparser {
1191
1191
  ResTarget(node, context) {
1192
1192
  const output = [];
1193
1193
  if (context.update && node.name) {
1194
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
1194
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
1195
1195
  // Handle indirection (array indexing, field access, etc.)
1196
1196
  if (node.indirection && node.indirection.length > 0) {
1197
1197
  const indirectionStrs = list_utils_1.ListUtils.unwrapList(node.indirection).map(item => {
1198
1198
  if (item.String) {
1199
- return `.${quote_utils_1.QuoteUtils.quote(item.String.sval || item.String.str)}`;
1199
+ return `.${quote_utils_1.QuoteUtils.quoteIdentifierAfterDot(item.String.sval || item.String.str)}`;
1200
1200
  }
1201
1201
  return this.visit(item, context);
1202
1202
  });
@@ -1208,12 +1208,12 @@ class Deparser {
1208
1208
  }
1209
1209
  }
1210
1210
  else if (context.insertColumns && node.name) {
1211
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
1211
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
1212
1212
  // Handle indirection for INSERT column lists (e.g., q.c1.r)
1213
1213
  if (node.indirection && node.indirection.length > 0) {
1214
1214
  const indirectionStrs = list_utils_1.ListUtils.unwrapList(node.indirection).map(item => {
1215
1215
  if (item.String) {
1216
- return `.${quote_utils_1.QuoteUtils.quote(item.String.sval || item.String.str)}`;
1216
+ return `.${quote_utils_1.QuoteUtils.quoteIdentifierAfterDot(item.String.sval || item.String.str)}`;
1217
1217
  }
1218
1218
  return this.visit(item, context);
1219
1219
  });
@@ -1226,7 +1226,7 @@ class Deparser {
1226
1226
  }
1227
1227
  if (node.name) {
1228
1228
  output.push('AS');
1229
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
1229
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
1230
1230
  }
1231
1231
  }
1232
1232
  return output.join(' ');
@@ -1240,7 +1240,7 @@ class Deparser {
1240
1240
  if (this.getNodeType(item) === 'ResTarget') {
1241
1241
  const resTarget = this.getNodeData(item);
1242
1242
  const val = resTarget.val ? this.visit(resTarget.val, context) : '';
1243
- const alias = resTarget.name ? ` AS ${quote_utils_1.QuoteUtils.quote(resTarget.name)}` : '';
1243
+ const alias = resTarget.name ? ` AS ${quote_utils_1.QuoteUtils.quoteIdentifier(resTarget.name)}` : '';
1244
1244
  return val + alias;
1245
1245
  }
1246
1246
  else {
@@ -1295,7 +1295,8 @@ class Deparser {
1295
1295
  FuncCall(node, context) {
1296
1296
  const funcname = list_utils_1.ListUtils.unwrapList(node.funcname);
1297
1297
  const args = list_utils_1.ListUtils.unwrapList(node.args);
1298
- const name = funcname.map(n => this.visit(n, context)).join('.');
1298
+ const funcnameParts = funcname.map((n) => n.String?.sval || n.String?.str || '').filter((s) => s);
1299
+ const name = quote_utils_1.QuoteUtils.quoteDottedName(funcnameParts);
1299
1300
  // Handle special SQL syntax functions like XMLEXISTS and EXTRACT
1300
1301
  if (node.funcformat === 'COERCE_SQL_SYNTAX' && name === 'pg_catalog.xmlexists' && args.length >= 2) {
1301
1302
  const xpath = this.visit(args[0], context);
@@ -1677,7 +1678,7 @@ class Deparser {
1677
1678
  const fields = list_utils_1.ListUtils.unwrapList(node.fields);
1678
1679
  return fields.map(field => {
1679
1680
  if (field.String) {
1680
- return quote_utils_1.QuoteUtils.quote(field.String.sval || field.String.str);
1681
+ return quote_utils_1.QuoteUtils.quoteIdentifier(field.String.sval || field.String.str);
1681
1682
  }
1682
1683
  else if (field.A_Star) {
1683
1684
  return '*';
@@ -1754,8 +1755,7 @@ class Deparser {
1754
1755
  }
1755
1756
  return output.join(' ');
1756
1757
  }
1757
- const quotedTypeName = quote_utils_1.QuoteUtils.quote(typeName);
1758
- let result = mods(quotedTypeName, args);
1758
+ let result = mods(typeName, args);
1759
1759
  if (node.arrayBounds && node.arrayBounds.length > 0) {
1760
1760
  result += formatArrayBounds(node.arrayBounds);
1761
1761
  }
@@ -1851,7 +1851,7 @@ class Deparser {
1851
1851
  return output.join(' ');
1852
1852
  }
1853
1853
  }
1854
- const quotedNames = names.map((name) => quote_utils_1.QuoteUtils.quote(name));
1854
+ const quotedNames = names.map((name) => quote_utils_1.QuoteUtils.quoteIdentifier(name));
1855
1855
  let result = mods(quotedNames.join('.'), args);
1856
1856
  if (node.arrayBounds && node.arrayBounds.length > 0) {
1857
1857
  result += formatArrayBounds(node.arrayBounds);
@@ -1890,17 +1890,17 @@ class Deparser {
1890
1890
  }
1891
1891
  let tableName = '';
1892
1892
  if (node.catalogname) {
1893
- tableName = quote_utils_1.QuoteUtils.quote(node.catalogname);
1893
+ tableName = quote_utils_1.QuoteUtils.quoteIdentifier(node.catalogname);
1894
1894
  if (node.schemaname) {
1895
- tableName += '.' + quote_utils_1.QuoteUtils.quote(node.schemaname);
1895
+ tableName += '.' + quote_utils_1.QuoteUtils.quoteIdentifierAfterDot(node.schemaname);
1896
1896
  }
1897
- tableName += '.' + quote_utils_1.QuoteUtils.quote(node.relname);
1897
+ tableName += '.' + quote_utils_1.QuoteUtils.quoteIdentifierAfterDot(node.relname);
1898
1898
  }
1899
1899
  else if (node.schemaname) {
1900
- tableName = quote_utils_1.QuoteUtils.quote(node.schemaname) + '.' + quote_utils_1.QuoteUtils.quote(node.relname);
1900
+ tableName = quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(node.schemaname, node.relname);
1901
1901
  }
1902
1902
  else {
1903
- tableName = quote_utils_1.QuoteUtils.quote(node.relname);
1903
+ tableName = quote_utils_1.QuoteUtils.quoteIdentifier(node.relname);
1904
1904
  }
1905
1905
  output.push(tableName);
1906
1906
  if (node.alias) {
@@ -2126,7 +2126,7 @@ class Deparser {
2126
2126
  const indirection = list_utils_1.ListUtils.unwrapList(node.indirection);
2127
2127
  for (const subnode of indirection) {
2128
2128
  if (subnode.String || subnode.A_Star) {
2129
- const value = subnode.A_Star ? '*' : quote_utils_1.QuoteUtils.quote(subnode.String.sval || subnode.String.str);
2129
+ const value = subnode.A_Star ? '*' : quote_utils_1.QuoteUtils.quoteIdentifier(subnode.String.sval || subnode.String.str);
2130
2130
  output.push(`.${value}`);
2131
2131
  }
2132
2132
  else {
@@ -2271,32 +2271,8 @@ class Deparser {
2271
2271
  }
2272
2272
  return output.join(' ');
2273
2273
  }
2274
- static RESERVED_WORDS = new Set([
2275
- 'all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'both',
2276
- 'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'current_catalog',
2277
- 'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user',
2278
- 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false',
2279
- 'fetch', 'for', 'foreign', 'from', 'grant', 'group', 'having', 'in', 'initially',
2280
- 'intersect', 'into', 'lateral', 'leading', 'limit', 'localtime', 'localtimestamp',
2281
- 'not', 'null', 'offset', 'on', 'only', 'or', 'order', 'placing', 'primary',
2282
- 'references', 'returning', 'select', 'session_user', 'some', 'symmetric', 'table',
2283
- 'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic',
2284
- 'when', 'where', 'window', 'with'
2285
- ]);
2286
- static needsQuotes(value) {
2287
- if (!value)
2288
- return false;
2289
- const needsQuotesRegex = /[a-z]+[\W\w]*[A-Z]+|[A-Z]+[\W\w]*[a-z]+|\W/;
2290
- const isAllUppercase = /^[A-Z]+$/.test(value);
2291
- return needsQuotesRegex.test(value) ||
2292
- Deparser.RESERVED_WORDS.has(value.toLowerCase()) ||
2293
- isAllUppercase;
2294
- }
2295
2274
  quoteIfNeeded(value) {
2296
- if (Deparser.needsQuotes(value)) {
2297
- return `"${value}"`;
2298
- }
2299
- return value;
2275
+ return quote_utils_1.QuoteUtils.quoteIdentifier(value);
2300
2276
  }
2301
2277
  preserveOperatorDefElemCase(defName) {
2302
2278
  const caseMap = {
@@ -2329,7 +2305,7 @@ class Deparser {
2329
2305
  return value; // Don't quote pure operator symbols like "=" or "-"
2330
2306
  }
2331
2307
  }
2332
- return Deparser.needsQuotes(value) ? `"${value}"` : value;
2308
+ return quote_utils_1.QuoteUtils.quoteIdentifier(value);
2333
2309
  }
2334
2310
  Integer(node, context) {
2335
2311
  return node.ival?.toString() || '0';
@@ -2506,7 +2482,7 @@ class Deparser {
2506
2482
  ColumnDef(node, context) {
2507
2483
  const output = [];
2508
2484
  if (node.colname) {
2509
- output.push(quote_utils_1.QuoteUtils.quote(node.colname));
2485
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.colname));
2510
2486
  }
2511
2487
  if (node.typeName) {
2512
2488
  output.push(this.TypeName(node.typeName, context));
@@ -2547,7 +2523,7 @@ class Deparser {
2547
2523
  // Handle constraint name if present
2548
2524
  if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN')) {
2549
2525
  output.push('CONSTRAINT');
2550
- output.push(quote_utils_1.QuoteUtils.quote(node.conname));
2526
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.conname));
2551
2527
  }
2552
2528
  switch (node.contype) {
2553
2529
  case 'CONSTR_NULL':
@@ -3444,7 +3420,7 @@ class Deparser {
3444
3420
  output.push('IF NOT EXISTS');
3445
3421
  }
3446
3422
  if (node.idxname) {
3447
- output.push(quote_utils_1.QuoteUtils.quote(node.idxname));
3423
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.idxname));
3448
3424
  }
3449
3425
  output.push('ON');
3450
3426
  if (node.relation) {
@@ -3478,14 +3454,14 @@ class Deparser {
3478
3454
  }
3479
3455
  if (node.tableSpace) {
3480
3456
  output.push('TABLESPACE');
3481
- output.push(quote_utils_1.QuoteUtils.quote(node.tableSpace));
3457
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.tableSpace));
3482
3458
  }
3483
3459
  return output.join(' ');
3484
3460
  }
3485
3461
  IndexElem(node, context) {
3486
3462
  const output = [];
3487
3463
  if (node.name) {
3488
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
3464
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
3489
3465
  }
3490
3466
  else if (node.expr) {
3491
3467
  output.push(context.parens(this.visit(node.expr, context)));
@@ -3536,7 +3512,7 @@ class Deparser {
3536
3512
  PartitionElem(node, context) {
3537
3513
  const output = [];
3538
3514
  if (node.name) {
3539
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
3515
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
3540
3516
  }
3541
3517
  else if (node.expr) {
3542
3518
  output.push(context.parens(this.visit(node.expr, context)));
@@ -3786,19 +3762,19 @@ class Deparser {
3786
3762
  case 'TRANS_STMT_SAVEPOINT':
3787
3763
  output.push('SAVEPOINT');
3788
3764
  if (node.savepoint_name) {
3789
- output.push(quote_utils_1.QuoteUtils.quote(node.savepoint_name));
3765
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.savepoint_name));
3790
3766
  }
3791
3767
  break;
3792
3768
  case 'TRANS_STMT_RELEASE':
3793
3769
  output.push('RELEASE SAVEPOINT');
3794
3770
  if (node.savepoint_name) {
3795
- output.push(quote_utils_1.QuoteUtils.quote(node.savepoint_name));
3771
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.savepoint_name));
3796
3772
  }
3797
3773
  break;
3798
3774
  case 'TRANS_STMT_ROLLBACK_TO':
3799
3775
  output.push('ROLLBACK TO');
3800
3776
  if (node.savepoint_name) {
3801
- output.push(quote_utils_1.QuoteUtils.quote(node.savepoint_name));
3777
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.savepoint_name));
3802
3778
  }
3803
3779
  break;
3804
3780
  case 'TRANS_STMT_PREPARE':
@@ -3895,16 +3871,16 @@ class Deparser {
3895
3871
  return this.visit(arg, context);
3896
3872
  }).join(', ') : '';
3897
3873
  // Handle args - always include TO clause if args exist (even if empty string)
3898
- const paramName = node.name && (node.name.includes('.') || node.name.includes('-') || /[A-Z]/.test(node.name)) ? `"${node.name}"` : node.name;
3874
+ const paramName = quote_utils_1.QuoteUtils.quoteIdentifier(node.name);
3899
3875
  if (!node.args || node.args.length === 0) {
3900
3876
  return `SET ${localPrefix}${paramName}`;
3901
3877
  }
3902
3878
  return `SET ${localPrefix}${paramName} TO ${args}`;
3903
3879
  case 'VAR_SET_DEFAULT':
3904
- const defaultParamName = node.name && (node.name.includes('.') || node.name.includes('-') || /[A-Z]/.test(node.name)) ? `"${node.name}"` : node.name;
3880
+ const defaultParamName = quote_utils_1.QuoteUtils.quoteIdentifier(node.name);
3905
3881
  return `SET ${defaultParamName} TO DEFAULT`;
3906
3882
  case 'VAR_SET_CURRENT':
3907
- const currentParamName = node.name && (node.name.includes('.') || node.name.includes('-') || /[A-Z]/.test(node.name)) ? `"${node.name}"` : node.name;
3883
+ const currentParamName = quote_utils_1.QuoteUtils.quoteIdentifier(node.name);
3908
3884
  return `SET ${currentParamName} FROM CURRENT`;
3909
3885
  case 'VAR_SET_MULTI':
3910
3886
  if (node.name === 'TRANSACTION' || node.name === 'SESSION CHARACTERISTICS') {
@@ -3978,7 +3954,7 @@ class Deparser {
3978
3954
  return `SET ${assignments}`;
3979
3955
  }
3980
3956
  case 'VAR_RESET':
3981
- const resetParamName = node.name && (node.name.includes('.') || node.name.includes('-') || /[A-Z]/.test(node.name)) ? `"${node.name}"` : node.name;
3957
+ const resetParamName = quote_utils_1.QuoteUtils.quoteIdentifier(node.name);
3982
3958
  return `RESET ${resetParamName}`;
3983
3959
  case 'VAR_RESET_ALL':
3984
3960
  return 'RESET ALL';
@@ -4247,7 +4223,7 @@ class Deparser {
4247
4223
  if (objList && objList.List && objList.List.items) {
4248
4224
  const items = objList.List.items.map((item) => {
4249
4225
  if (item.String && item.String.sval) {
4250
- return quote_utils_1.QuoteUtils.quote(item.String.sval);
4226
+ return quote_utils_1.QuoteUtils.quoteIdentifier(item.String.sval);
4251
4227
  }
4252
4228
  return this.visit(item, context);
4253
4229
  }).filter((name) => name && name.trim());
@@ -4281,13 +4257,13 @@ class Deparser {
4281
4257
  if (items.length === 2) {
4282
4258
  const accessMethod = items[0];
4283
4259
  const objectName = items[1];
4284
- return `${quote_utils_1.QuoteUtils.quote(objectName)} USING ${accessMethod}`;
4260
+ return `${quote_utils_1.QuoteUtils.quoteIdentifier(objectName)} USING ${accessMethod}`;
4285
4261
  }
4286
4262
  else if (items.length === 3) {
4287
4263
  const accessMethod = items[0];
4288
4264
  const schemaName = items[1];
4289
4265
  const objectName = items[2];
4290
- return `${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(objectName)} USING ${accessMethod}`;
4266
+ return `${quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, objectName)} USING ${accessMethod}`;
4291
4267
  }
4292
4268
  return items.join('.');
4293
4269
  }
@@ -4330,7 +4306,7 @@ class Deparser {
4330
4306
  if (objList && objList.List && objList.List.items) {
4331
4307
  const items = objList.List.items.map((item) => {
4332
4308
  if (item.String && item.String.sval) {
4333
- return quote_utils_1.QuoteUtils.quote(item.String.sval);
4309
+ return quote_utils_1.QuoteUtils.quoteIdentifier(item.String.sval);
4334
4310
  }
4335
4311
  return this.visit(item, context);
4336
4312
  }).filter((name) => name && name.trim());
@@ -4378,7 +4354,7 @@ class Deparser {
4378
4354
  PLAssignStmt(node, context) {
4379
4355
  const output = [];
4380
4356
  if (node.name) {
4381
- let nameWithIndirection = quote_utils_1.QuoteUtils.quote(node.name);
4357
+ let nameWithIndirection = quote_utils_1.QuoteUtils.quoteIdentifier(node.name);
4382
4358
  if (node.indirection && node.indirection.length > 0) {
4383
4359
  const indirectionStr = node.indirection
4384
4360
  .map((ind) => this.visit(ind, context))
@@ -4527,7 +4503,7 @@ class Deparser {
4527
4503
  const parts = [];
4528
4504
  const indentedParts = [];
4529
4505
  if (colDefData.colname) {
4530
- parts.push(quote_utils_1.QuoteUtils.quote(colDefData.colname));
4506
+ parts.push(quote_utils_1.QuoteUtils.quoteIdentifier(colDefData.colname));
4531
4507
  }
4532
4508
  if (colDefData.typeName) {
4533
4509
  parts.push(this.TypeName(colDefData.typeName, context));
@@ -4585,7 +4561,7 @@ class Deparser {
4585
4561
  else {
4586
4562
  const parts = [];
4587
4563
  if (colDefData.colname) {
4588
- parts.push(quote_utils_1.QuoteUtils.quote(colDefData.colname));
4564
+ parts.push(quote_utils_1.QuoteUtils.quoteIdentifier(colDefData.colname));
4589
4565
  }
4590
4566
  if (colDefData.typeName) {
4591
4567
  parts.push(this.TypeName(colDefData.typeName, context));
@@ -4639,7 +4615,7 @@ class Deparser {
4639
4615
  }
4640
4616
  }
4641
4617
  if (node.name) {
4642
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4618
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4643
4619
  }
4644
4620
  if (node.behavior === 'DROP_CASCADE') {
4645
4621
  output.push('CASCADE');
@@ -4656,7 +4632,7 @@ class Deparser {
4656
4632
  output.push('ALTER COLUMN');
4657
4633
  }
4658
4634
  if (node.name) {
4659
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4635
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4660
4636
  }
4661
4637
  output.push('TYPE');
4662
4638
  if (node.def) {
@@ -4683,7 +4659,7 @@ class Deparser {
4683
4659
  case 'AT_SetTableSpace':
4684
4660
  output.push('SET TABLESPACE');
4685
4661
  if (node.name) {
4686
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4662
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4687
4663
  }
4688
4664
  break;
4689
4665
  case 'AT_AddConstraint':
@@ -4701,7 +4677,7 @@ class Deparser {
4701
4677
  output.push('DROP CONSTRAINT');
4702
4678
  }
4703
4679
  if (node.name) {
4704
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4680
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4705
4681
  }
4706
4682
  if (node.behavior === 'DROP_CASCADE') {
4707
4683
  output.push('CASCADE');
@@ -4739,7 +4715,7 @@ class Deparser {
4739
4715
  case 'AT_ColumnDefault':
4740
4716
  output.push('ALTER COLUMN');
4741
4717
  if (node.name) {
4742
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4718
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4743
4719
  }
4744
4720
  if (node.def) {
4745
4721
  output.push('SET DEFAULT');
@@ -4752,7 +4728,7 @@ class Deparser {
4752
4728
  case 'AT_SetStorage':
4753
4729
  output.push('ALTER COLUMN');
4754
4730
  if (node.name) {
4755
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4731
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4756
4732
  }
4757
4733
  output.push('SET STORAGE');
4758
4734
  if (node.def) {
@@ -4763,7 +4739,7 @@ class Deparser {
4763
4739
  case 'AT_ClusterOn':
4764
4740
  output.push('CLUSTER ON');
4765
4741
  if (node.name) {
4766
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4742
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4767
4743
  }
4768
4744
  break;
4769
4745
  case 'AT_DropCluster':
@@ -4790,21 +4766,21 @@ class Deparser {
4790
4766
  case 'AT_SetNotNull':
4791
4767
  output.push('ALTER COLUMN');
4792
4768
  if (node.name) {
4793
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4769
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4794
4770
  }
4795
4771
  output.push('SET NOT NULL');
4796
4772
  break;
4797
4773
  case 'AT_DropNotNull':
4798
4774
  output.push('ALTER COLUMN');
4799
4775
  if (node.name) {
4800
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4776
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4801
4777
  }
4802
4778
  output.push('DROP NOT NULL');
4803
4779
  break;
4804
4780
  case 'AT_SetStatistics':
4805
4781
  output.push('ALTER COLUMN');
4806
4782
  if (node.name) {
4807
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4783
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4808
4784
  }
4809
4785
  else if (node.num !== undefined && node.num !== null) {
4810
4786
  output.push(node.num.toString());
@@ -4817,7 +4793,7 @@ class Deparser {
4817
4793
  case 'AT_SetOptions':
4818
4794
  output.push('ALTER COLUMN');
4819
4795
  if (node.name) {
4820
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4796
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4821
4797
  }
4822
4798
  output.push('SET');
4823
4799
  if (node.def) {
@@ -4834,7 +4810,7 @@ class Deparser {
4834
4810
  case 'AT_ResetOptions':
4835
4811
  output.push('ALTER COLUMN');
4836
4812
  if (node.name) {
4837
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4813
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4838
4814
  }
4839
4815
  output.push('RESET');
4840
4816
  if (node.def) {
@@ -4851,7 +4827,7 @@ class Deparser {
4851
4827
  case 'AT_SetCompression':
4852
4828
  output.push('ALTER COLUMN');
4853
4829
  if (node.name) {
4854
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4830
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4855
4831
  }
4856
4832
  output.push('SET COMPRESSION');
4857
4833
  if (node.def) {
@@ -4861,31 +4837,31 @@ class Deparser {
4861
4837
  case 'AT_ValidateConstraint':
4862
4838
  output.push('VALIDATE CONSTRAINT');
4863
4839
  if (node.name) {
4864
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4840
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4865
4841
  }
4866
4842
  break;
4867
4843
  case 'AT_EnableTrig':
4868
4844
  output.push('ENABLE TRIGGER');
4869
4845
  if (node.name) {
4870
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4846
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4871
4847
  }
4872
4848
  break;
4873
4849
  case 'AT_EnableAlwaysTrig':
4874
4850
  output.push('ENABLE ALWAYS TRIGGER');
4875
4851
  if (node.name) {
4876
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4852
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4877
4853
  }
4878
4854
  break;
4879
4855
  case 'AT_EnableReplicaTrig':
4880
4856
  output.push('ENABLE REPLICA TRIGGER');
4881
4857
  if (node.name) {
4882
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4858
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4883
4859
  }
4884
4860
  break;
4885
4861
  case 'AT_DisableTrig':
4886
4862
  output.push('DISABLE TRIGGER');
4887
4863
  if (node.name) {
4888
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4864
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4889
4865
  }
4890
4866
  break;
4891
4867
  case 'AT_EnableTrigAll':
@@ -4903,31 +4879,31 @@ class Deparser {
4903
4879
  case 'AT_EnableRule':
4904
4880
  output.push('ENABLE RULE');
4905
4881
  if (node.name) {
4906
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4882
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4907
4883
  }
4908
4884
  break;
4909
4885
  case 'AT_EnableAlwaysRule':
4910
4886
  output.push('ENABLE ALWAYS RULE');
4911
4887
  if (node.name) {
4912
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4888
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4913
4889
  }
4914
4890
  break;
4915
4891
  case 'AT_EnableReplicaRule':
4916
4892
  output.push('ENABLE REPLICA RULE');
4917
4893
  if (node.name) {
4918
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4894
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4919
4895
  }
4920
4896
  break;
4921
4897
  case 'AT_DisableRule':
4922
4898
  output.push('DISABLE RULE');
4923
4899
  if (node.name) {
4924
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4900
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4925
4901
  }
4926
4902
  break;
4927
4903
  case 'AT_SetAccessMethod':
4928
4904
  output.push('SET ACCESS METHOD');
4929
4905
  if (node.name) {
4930
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4906
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4931
4907
  }
4932
4908
  else {
4933
4909
  // Handle DEFAULT access method case
@@ -4981,7 +4957,7 @@ class Deparser {
4981
4957
  case 'AT_CookedColumnDefault':
4982
4958
  output.push('ALTER COLUMN');
4983
4959
  if (node.name) {
4984
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4960
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4985
4961
  }
4986
4962
  if (node.def) {
4987
4963
  output.push('SET DEFAULT');
@@ -4994,7 +4970,7 @@ class Deparser {
4994
4970
  case 'AT_SetExpression':
4995
4971
  output.push('ALTER COLUMN');
4996
4972
  if (node.name) {
4997
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4973
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
4998
4974
  }
4999
4975
  output.push('SET EXPRESSION');
5000
4976
  if (node.def) {
@@ -5004,14 +4980,14 @@ class Deparser {
5004
4980
  case 'AT_DropExpression':
5005
4981
  output.push('ALTER COLUMN');
5006
4982
  if (node.name) {
5007
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4983
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
5008
4984
  }
5009
4985
  output.push('DROP EXPRESSION');
5010
4986
  break;
5011
4987
  case 'AT_CheckNotNull':
5012
4988
  output.push('ALTER COLUMN');
5013
4989
  if (node.name) {
5014
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
4990
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
5015
4991
  }
5016
4992
  output.push('SET NOT NULL');
5017
4993
  break;
@@ -5044,7 +5020,7 @@ class Deparser {
5044
5020
  if (node.def && this.getNodeType(node.def) === 'Constraint') {
5045
5021
  const constraintData = this.getNodeData(node.def);
5046
5022
  if (constraintData.conname) {
5047
- output.push(quote_utils_1.QuoteUtils.quote(constraintData.conname));
5023
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(constraintData.conname));
5048
5024
  if (constraintData.deferrable !== undefined) {
5049
5025
  output.push(constraintData.deferrable ? 'DEFERRABLE' : 'NOT DEFERRABLE');
5050
5026
  }
@@ -5054,7 +5030,7 @@ class Deparser {
5054
5030
  }
5055
5031
  }
5056
5032
  else if (node.name) {
5057
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
5033
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
5058
5034
  if (node.def) {
5059
5035
  output.push(this.visit(node.def, context));
5060
5036
  }
@@ -5075,7 +5051,7 @@ class Deparser {
5075
5051
  case 'AT_AlterColumnGenericOptions':
5076
5052
  output.push('ALTER COLUMN');
5077
5053
  if (node.name) {
5078
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
5054
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
5079
5055
  }
5080
5056
  output.push('OPTIONS');
5081
5057
  if (node.def) {
@@ -5129,7 +5105,7 @@ class Deparser {
5129
5105
  case 'AT_AddIdentity':
5130
5106
  output.push('ALTER COLUMN');
5131
5107
  if (node.name) {
5132
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
5108
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
5133
5109
  }
5134
5110
  output.push('ADD');
5135
5111
  if (node.def) {
@@ -5139,7 +5115,7 @@ class Deparser {
5139
5115
  case 'AT_SetIdentity':
5140
5116
  output.push('ALTER COLUMN');
5141
5117
  if (node.name) {
5142
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
5118
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
5143
5119
  }
5144
5120
  output.push('SET');
5145
5121
  if (node.def) {
@@ -5149,7 +5125,7 @@ class Deparser {
5149
5125
  case 'AT_DropIdentity':
5150
5126
  output.push('ALTER COLUMN');
5151
5127
  if (node.name) {
5152
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
5128
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
5153
5129
  }
5154
5130
  output.push('DROP IDENTITY');
5155
5131
  if (node.behavior === 'DROP_CASCADE') {
@@ -5183,7 +5159,8 @@ class Deparser {
5183
5159
  output.push('FUNCTION');
5184
5160
  }
5185
5161
  if (node.funcname && node.funcname.length > 0) {
5186
- const funcName = node.funcname.map((name) => this.visit(name, context)).join('.');
5162
+ const funcnameParts = node.funcname.map((name) => name.String?.sval || name.String?.str || '').filter((s) => s);
5163
+ const funcName = quote_utils_1.QuoteUtils.quoteDottedName(funcnameParts);
5187
5164
  if (node.parameters && node.parameters.length > 0) {
5188
5165
  const params = node.parameters
5189
5166
  .filter((param) => {
@@ -5288,7 +5265,7 @@ class Deparser {
5288
5265
  }
5289
5266
  }
5290
5267
  if (node.name) {
5291
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
5268
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
5292
5269
  }
5293
5270
  if (node.argType) {
5294
5271
  output.push(this.TypeName(node.argType, context));
@@ -5360,7 +5337,7 @@ class Deparser {
5360
5337
  output.push('ROLE');
5361
5338
  }
5362
5339
  if (node.role) {
5363
- const roleName = Deparser.needsQuotes(node.role) ? `"${node.role}"` : node.role;
5340
+ const roleName = quote_utils_1.QuoteUtils.quoteIdentifier(node.role);
5364
5341
  output.push(roleName);
5365
5342
  }
5366
5343
  if (node.options) {
@@ -5402,7 +5379,7 @@ class Deparser {
5402
5379
  if (context.parentNodeTypes.includes('DefineStmt') &&
5403
5380
  ['hashes', 'merges'].includes(node.defname.toLowerCase()) && !node.arg) {
5404
5381
  if (node.defname !== node.defname.toLowerCase() && node.defname !== node.defname.toUpperCase()) {
5405
- return `"${node.defname}"`;
5382
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.defname);
5406
5383
  }
5407
5384
  return node.defname.charAt(0).toUpperCase() + node.defname.slice(1).toLowerCase();
5408
5385
  }
@@ -5424,9 +5401,7 @@ class Deparser {
5424
5401
  const finalValue = typeof argValue === 'string' && !argValue.startsWith("'")
5425
5402
  ? `'${argValue}'`
5426
5403
  : argValue;
5427
- const quotedDefname = node.defname.includes(' ') || node.defname.includes('-') || Deparser.needsQuotes(node.defname)
5428
- ? `"${node.defname}"`
5429
- : node.defname;
5404
+ const quotedDefname = quote_utils_1.QuoteUtils.quoteIdentifier(node.defname);
5430
5405
  if (node.defaction === 'DEFELEM_ADD') {
5431
5406
  return `ADD ${quotedDefname} ${finalValue}`;
5432
5407
  }
@@ -5450,9 +5425,7 @@ class Deparser {
5450
5425
  else if (node.defaction === 'DEFELEM_SET') {
5451
5426
  return `SET ${node.defname} ${quotedValue}`;
5452
5427
  }
5453
- const quotedDefname = node.defname.includes(' ') || node.defname.includes('-')
5454
- ? `"${node.defname}"`
5455
- : node.defname;
5428
+ const quotedDefname = quote_utils_1.QuoteUtils.quoteIdentifier(node.defname);
5456
5429
  return `${quotedDefname} ${quotedValue}`;
5457
5430
  }
5458
5431
  else if (node.defaction === 'DEFELEM_DROP') {
@@ -5512,9 +5485,7 @@ class Deparser {
5512
5485
  const quotedValue = typeof argValue === 'string'
5513
5486
  ? quote_utils_1.QuoteUtils.escape(argValue)
5514
5487
  : argValue;
5515
- const quotedDefname = node.defname.includes(' ') || node.defname.includes('-')
5516
- ? `"${node.defname}"`
5517
- : node.defname;
5488
+ const quotedDefname = quote_utils_1.QuoteUtils.quoteIdentifier(node.defname);
5518
5489
  return `${quotedDefname} ${quotedValue}`;
5519
5490
  }
5520
5491
  if (context.parentNodeTypes.includes('CreateRoleStmt') || context.parentNodeTypes.includes('AlterRoleStmt')) {
@@ -5589,10 +5560,7 @@ class Deparser {
5589
5560
  if (this.getNodeType(item) === 'String') {
5590
5561
  // Check if this identifier needs quotes to preserve case
5591
5562
  const value = itemData.sval;
5592
- if (Deparser.needsQuotes(value)) {
5593
- return `"${value}"`;
5594
- }
5595
- return value;
5563
+ return quote_utils_1.QuoteUtils.quoteIdentifier(value);
5596
5564
  }
5597
5565
  return this.visit(item, context);
5598
5566
  });
@@ -5840,13 +5808,13 @@ class Deparser {
5840
5808
  // Handle boolean flags (no arguments) - preserve quoted case
5841
5809
  if (['hashes', 'merges'].includes(node.defname.toLowerCase())) {
5842
5810
  if (node.defname !== node.defname.toLowerCase() && node.defname !== node.defname.toUpperCase()) {
5843
- return `"${node.defname}"`;
5811
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.defname);
5844
5812
  }
5845
5813
  return preservedName.toUpperCase();
5846
5814
  }
5847
5815
  // Handle CREATE AGGREGATE quoted identifiers - preserve quotes when needed
5848
- if (Deparser.needsQuotes(node.defname)) {
5849
- const quotedDefname = `"${node.defname}"`;
5816
+ const quotedDefname = quote_utils_1.QuoteUtils.quoteIdentifier(node.defname);
5817
+ if (quotedDefname !== node.defname) {
5850
5818
  if (node.arg) {
5851
5819
  if (this.getNodeType(node.arg) === 'String') {
5852
5820
  const stringData = this.getNodeData(node.arg);
@@ -5906,7 +5874,7 @@ class Deparser {
5906
5874
  if (context.parentNodeTypes.includes('DefineStmt') && !node.arg) {
5907
5875
  // Check if the original defname appears to be quoted (mixed case that's not all upper/lower)
5908
5876
  if (node.defname !== node.defname.toLowerCase() && node.defname !== node.defname.toUpperCase()) {
5909
- return `"${node.defname}"`;
5877
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.defname);
5910
5878
  }
5911
5879
  }
5912
5880
  return node.defname.toUpperCase();
@@ -6090,7 +6058,7 @@ class Deparser {
6090
6058
  case 'REPLICA_IDENTITY_INDEX':
6091
6059
  output.push('USING', 'INDEX');
6092
6060
  if (node.name) {
6093
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
6061
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
6094
6062
  }
6095
6063
  break;
6096
6064
  default:
@@ -6149,7 +6117,7 @@ class Deparser {
6149
6117
  output.push('IF', 'EXISTS');
6150
6118
  }
6151
6119
  if (node.name) {
6152
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
6120
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
6153
6121
  }
6154
6122
  if (node.behavior === 'DROP_CASCADE') {
6155
6123
  output.push('CASCADE');
@@ -6158,7 +6126,7 @@ class Deparser {
6158
6126
  case 'AT_ValidateConstraint':
6159
6127
  output.push('VALIDATE', 'CONSTRAINT');
6160
6128
  if (node.name) {
6161
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
6129
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
6162
6130
  }
6163
6131
  break;
6164
6132
  case 'C':
@@ -6175,7 +6143,7 @@ class Deparser {
6175
6143
  output.push('IF', 'EXISTS');
6176
6144
  }
6177
6145
  if (node.name) {
6178
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
6146
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
6179
6147
  }
6180
6148
  if (node.behavior === 'DROP_CASCADE') {
6181
6149
  output.push('CASCADE');
@@ -6184,7 +6152,7 @@ class Deparser {
6184
6152
  case 'V':
6185
6153
  output.push('VALIDATE', 'CONSTRAINT');
6186
6154
  if (node.name) {
6187
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
6155
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
6188
6156
  }
6189
6157
  break;
6190
6158
  case 'O':
@@ -6573,7 +6541,7 @@ class Deparser {
6573
6541
  const output = [];
6574
6542
  const initialParts = ['CREATE', 'POLICY'];
6575
6543
  if (node.policy_name) {
6576
- initialParts.push(quote_utils_1.QuoteUtils.quote(node.policy_name));
6544
+ initialParts.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.policy_name));
6577
6545
  }
6578
6546
  output.push(initialParts.join(' '));
6579
6547
  // Add ON clause on new line in pretty mode
@@ -6650,7 +6618,7 @@ class Deparser {
6650
6618
  AlterPolicyStmt(node, context) {
6651
6619
  const output = ['ALTER', 'POLICY'];
6652
6620
  if (node.policy_name) {
6653
- output.push(quote_utils_1.QuoteUtils.quote(node.policy_name));
6621
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.policy_name));
6654
6622
  }
6655
6623
  if (node.table) {
6656
6624
  output.push('ON');
@@ -6686,7 +6654,7 @@ class Deparser {
6686
6654
  }
6687
6655
  output.push('SERVER');
6688
6656
  if (node.servername) {
6689
- output.push(`"${node.servername}"`);
6657
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.servername));
6690
6658
  }
6691
6659
  if (node.options && node.options.length > 0) {
6692
6660
  output.push('OPTIONS');
@@ -6734,7 +6702,7 @@ class Deparser {
6734
6702
  CreatePublicationStmt(node, context) {
6735
6703
  const output = ['CREATE', 'PUBLICATION'];
6736
6704
  if (node.pubname) {
6737
- output.push(`"${node.pubname}"`);
6705
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.pubname));
6738
6706
  }
6739
6707
  if (node.pubobjects && node.pubobjects.length > 0) {
6740
6708
  output.push('FOR', 'TABLE');
@@ -6754,7 +6722,7 @@ class Deparser {
6754
6722
  CreateSubscriptionStmt(node, context) {
6755
6723
  const output = ['CREATE', 'SUBSCRIPTION'];
6756
6724
  if (node.subname) {
6757
- output.push(`"${node.subname}"`);
6725
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.subname));
6758
6726
  }
6759
6727
  output.push('CONNECTION');
6760
6728
  if (node.conninfo) {
@@ -6775,7 +6743,7 @@ class Deparser {
6775
6743
  AlterPublicationStmt(node, context) {
6776
6744
  const output = ['ALTER', 'PUBLICATION'];
6777
6745
  if (node.pubname) {
6778
- output.push(`"${node.pubname}"`);
6746
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.pubname));
6779
6747
  }
6780
6748
  if (node.action) {
6781
6749
  switch (node.action) {
@@ -6810,7 +6778,7 @@ class Deparser {
6810
6778
  AlterSubscriptionStmt(node, context) {
6811
6779
  const output = ['ALTER', 'SUBSCRIPTION'];
6812
6780
  if (node.subname) {
6813
- output.push(`"${node.subname}"`);
6781
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.subname));
6814
6782
  }
6815
6783
  if (node.kind) {
6816
6784
  switch (node.kind) {
@@ -6856,7 +6824,7 @@ class Deparser {
6856
6824
  output.push('IF EXISTS');
6857
6825
  }
6858
6826
  if (node.subname) {
6859
- output.push(`"${node.subname}"`);
6827
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.subname));
6860
6828
  }
6861
6829
  if (node.behavior) {
6862
6830
  switch (node.behavior) {
@@ -7101,7 +7069,7 @@ class Deparser {
7101
7069
  ClosePortalStmt(node, context) {
7102
7070
  const output = ['CLOSE'];
7103
7071
  if (node.portalname) {
7104
- output.push(quote_utils_1.QuoteUtils.quote(node.portalname));
7072
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.portalname));
7105
7073
  }
7106
7074
  else {
7107
7075
  output.push('ALL');
@@ -7159,7 +7127,7 @@ class Deparser {
7159
7127
  output.push('ALL');
7160
7128
  }
7161
7129
  if (node.portalname) {
7162
- output.push(quote_utils_1.QuoteUtils.quote(node.portalname));
7130
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.portalname));
7163
7131
  }
7164
7132
  return output.join(' ');
7165
7133
  }
@@ -7229,7 +7197,7 @@ class Deparser {
7229
7197
  AlterFdwStmt(node, context) {
7230
7198
  const output = ['ALTER', 'FOREIGN', 'DATA', 'WRAPPER'];
7231
7199
  if (node.fdwname) {
7232
- output.push(quote_utils_1.QuoteUtils.quote(node.fdwname));
7200
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.fdwname));
7233
7201
  }
7234
7202
  if (node.func_options && node.func_options.length > 0) {
7235
7203
  const fdwContext = context.spawn('AlterFdwStmt');
@@ -7250,7 +7218,7 @@ class Deparser {
7250
7218
  output.push('IF', 'NOT', 'EXISTS');
7251
7219
  }
7252
7220
  if (node.servername) {
7253
- output.push(quote_utils_1.QuoteUtils.quote(node.servername));
7221
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.servername));
7254
7222
  }
7255
7223
  if (node.servertype) {
7256
7224
  output.push('TYPE', quote_utils_1.QuoteUtils.escape(node.servertype));
@@ -7259,7 +7227,7 @@ class Deparser {
7259
7227
  output.push('VERSION', quote_utils_1.QuoteUtils.escape(node.version));
7260
7228
  }
7261
7229
  if (node.fdwname) {
7262
- output.push('FOREIGN', 'DATA', 'WRAPPER', quote_utils_1.QuoteUtils.quote(node.fdwname));
7230
+ output.push('FOREIGN', 'DATA', 'WRAPPER', quote_utils_1.QuoteUtils.quoteIdentifier(node.fdwname));
7263
7231
  }
7264
7232
  if (node.options && node.options.length > 0) {
7265
7233
  output.push('OPTIONS');
@@ -7274,7 +7242,7 @@ class Deparser {
7274
7242
  AlterForeignServerStmt(node, context) {
7275
7243
  const output = ['ALTER', 'SERVER'];
7276
7244
  if (node.servername) {
7277
- output.push(quote_utils_1.QuoteUtils.quote(node.servername));
7245
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.servername));
7278
7246
  }
7279
7247
  if (node.version) {
7280
7248
  output.push('VERSION', quote_utils_1.QuoteUtils.escape(node.version));
@@ -7299,7 +7267,7 @@ class Deparser {
7299
7267
  }
7300
7268
  output.push('SERVER');
7301
7269
  if (node.servername) {
7302
- output.push(quote_utils_1.QuoteUtils.quote(node.servername));
7270
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.servername));
7303
7271
  }
7304
7272
  if (node.options && node.options.length > 0) {
7305
7273
  output.push('OPTIONS');
@@ -7323,14 +7291,14 @@ class Deparser {
7323
7291
  }
7324
7292
  output.push('SERVER');
7325
7293
  if (node.servername) {
7326
- output.push(quote_utils_1.QuoteUtils.quote(node.servername));
7294
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.servername));
7327
7295
  }
7328
7296
  return output.join(' ');
7329
7297
  }
7330
7298
  ImportForeignSchemaStmt(node, context) {
7331
7299
  const output = ['IMPORT', 'FOREIGN', 'SCHEMA'];
7332
7300
  if (node.remote_schema) {
7333
- output.push(quote_utils_1.QuoteUtils.quote(node.remote_schema));
7301
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.remote_schema));
7334
7302
  }
7335
7303
  if (node.list_type) {
7336
7304
  switch (node.list_type) {
@@ -7356,11 +7324,11 @@ class Deparser {
7356
7324
  }
7357
7325
  output.push('FROM', 'SERVER');
7358
7326
  if (node.server_name) {
7359
- output.push(quote_utils_1.QuoteUtils.quote(node.server_name));
7327
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.server_name));
7360
7328
  }
7361
7329
  output.push('INTO');
7362
7330
  if (node.local_schema) {
7363
- output.push(quote_utils_1.QuoteUtils.quote(node.local_schema));
7331
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.local_schema));
7364
7332
  }
7365
7333
  if (node.options && node.options.length > 0) {
7366
7334
  const importSchemaContext = context.spawn('ImportForeignSchemaStmt');
@@ -7374,7 +7342,7 @@ class Deparser {
7374
7342
  if (node.relation) {
7375
7343
  output.push(this.RangeVar(node.relation, context));
7376
7344
  if (node.indexname) {
7377
- output.push('USING', `"${node.indexname}"`);
7345
+ output.push('USING', quote_utils_1.QuoteUtils.quoteIdentifier(node.indexname));
7378
7346
  }
7379
7347
  }
7380
7348
  if (node.params && node.params.length > 0) {
@@ -7438,7 +7406,7 @@ class Deparser {
7438
7406
  output.push(this.RangeVar(node.relation, context));
7439
7407
  }
7440
7408
  if (node.name) {
7441
- output.push(`"${node.name}"`);
7409
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
7442
7410
  }
7443
7411
  return output.join(' ');
7444
7412
  }
@@ -7478,7 +7446,7 @@ class Deparser {
7478
7446
  if (!node.dbname) {
7479
7447
  throw new Error('CreatedbStmt requires dbname');
7480
7448
  }
7481
- output.push(`"${node.dbname}"`);
7449
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.dbname));
7482
7450
  if (node.options && node.options.length > 0) {
7483
7451
  const options = list_utils_1.ListUtils.unwrapList(node.options)
7484
7452
  .map(option => this.visit(option, context))
@@ -7495,7 +7463,7 @@ class Deparser {
7495
7463
  if (!node.dbname) {
7496
7464
  throw new Error('DropdbStmt requires dbname');
7497
7465
  }
7498
- output.push(`"${node.dbname}"`);
7466
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.dbname));
7499
7467
  if (node.options && node.options.length > 0) {
7500
7468
  const options = list_utils_1.ListUtils.unwrapList(node.options)
7501
7469
  .map(option => this.visit(option, context))
@@ -7593,7 +7561,7 @@ class Deparser {
7593
7561
  case 'OBJECT_POLICY':
7594
7562
  output.push('POLICY');
7595
7563
  if (node.subname) {
7596
- output.push(quote_utils_1.QuoteUtils.quote(node.subname));
7564
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.subname));
7597
7565
  }
7598
7566
  break;
7599
7567
  case 'OBJECT_PUBLICATION':
@@ -7651,7 +7619,7 @@ class Deparser {
7651
7619
  }
7652
7620
  // Handle OBJECT_RULE special case: rule_name ON table_name format
7653
7621
  if (node.renameType === 'OBJECT_RULE' && node.subname && node.relation) {
7654
- output.push(quote_utils_1.QuoteUtils.quote(node.subname));
7622
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.subname));
7655
7623
  output.push('ON');
7656
7624
  output.push(this.RangeVar(node.relation, context));
7657
7625
  }
@@ -7670,7 +7638,7 @@ class Deparser {
7670
7638
  if (items.length === 2) {
7671
7639
  const accessMethod = items[0].String?.sval || '';
7672
7640
  const objectName = items[1].String?.sval || '';
7673
- output.push(`${quote_utils_1.QuoteUtils.quote(objectName)} USING ${accessMethod}`);
7641
+ output.push(`${quote_utils_1.QuoteUtils.quoteIdentifier(objectName)} USING ${accessMethod}`);
7674
7642
  }
7675
7643
  else {
7676
7644
  output.push(this.visit(node.object, context));
@@ -7691,19 +7659,19 @@ class Deparser {
7691
7659
  }
7692
7660
  }
7693
7661
  if (node.renameType === 'OBJECT_COLUMN' && node.subname) {
7694
- output.push('RENAME COLUMN', `"${node.subname}"`, 'TO');
7662
+ output.push('RENAME COLUMN', quote_utils_1.QuoteUtils.quoteIdentifier(node.subname), 'TO');
7695
7663
  }
7696
7664
  else if (node.renameType === 'OBJECT_DOMCONSTRAINT' && node.subname) {
7697
- output.push('RENAME CONSTRAINT', `"${node.subname}"`, 'TO');
7665
+ output.push('RENAME CONSTRAINT', quote_utils_1.QuoteUtils.quoteIdentifier(node.subname), 'TO');
7698
7666
  }
7699
7667
  else if (node.renameType === 'OBJECT_TABCONSTRAINT' && node.subname) {
7700
- output.push('RENAME CONSTRAINT', `"${node.subname}"`, 'TO');
7668
+ output.push('RENAME CONSTRAINT', quote_utils_1.QuoteUtils.quoteIdentifier(node.subname), 'TO');
7701
7669
  }
7702
7670
  else if (node.renameType === 'OBJECT_ATTRIBUTE' && node.subname) {
7703
- output.push('RENAME ATTRIBUTE', `"${node.subname}"`, 'TO');
7671
+ output.push('RENAME ATTRIBUTE', quote_utils_1.QuoteUtils.quoteIdentifier(node.subname), 'TO');
7704
7672
  }
7705
7673
  else if (node.renameType === 'OBJECT_ROLE' && node.subname) {
7706
- output.push(`"${node.subname}"`, 'RENAME TO');
7674
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.subname), 'RENAME TO');
7707
7675
  }
7708
7676
  else if (node.renameType === 'OBJECT_SCHEMA' && node.subname) {
7709
7677
  output.push(this.quoteIfNeeded(node.subname), 'RENAME TO');
@@ -7717,7 +7685,7 @@ class Deparser {
7717
7685
  if (!node.newname) {
7718
7686
  throw new Error('RenameStmt requires newname');
7719
7687
  }
7720
- output.push(quote_utils_1.QuoteUtils.quote(node.newname));
7688
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.newname));
7721
7689
  // Handle CASCADE/RESTRICT behavior for RENAME operations
7722
7690
  if (node.behavior === 'DROP_CASCADE') {
7723
7691
  output.push('CASCADE');
@@ -7740,7 +7708,7 @@ class Deparser {
7740
7708
  if (items.length === 2) {
7741
7709
  const accessMethod = items[0].String?.sval || '';
7742
7710
  const objectName = items[1].String?.sval || '';
7743
- output.push(`${quote_utils_1.QuoteUtils.quote(objectName)} USING ${accessMethod}`);
7711
+ output.push(`${quote_utils_1.QuoteUtils.quoteIdentifier(objectName)} USING ${accessMethod}`);
7744
7712
  }
7745
7713
  else {
7746
7714
  output.push(this.visit(node.object, context));
@@ -8010,7 +7978,7 @@ class Deparser {
8010
7978
  SecLabelStmt(node, context) {
8011
7979
  const output = ['SECURITY LABEL'];
8012
7980
  if (node.provider) {
8013
- output.push('FOR', `"${node.provider}"`);
7981
+ output.push('FOR', quote_utils_1.QuoteUtils.quoteIdentifier(node.provider));
8014
7982
  }
8015
7983
  output.push('ON');
8016
7984
  if (node.objtype) {
@@ -8163,7 +8131,7 @@ class Deparser {
8163
8131
  }
8164
8132
  output.push('LANGUAGE');
8165
8133
  if (node.plname) {
8166
- output.push(quote_utils_1.QuoteUtils.quote(node.plname));
8134
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.plname));
8167
8135
  }
8168
8136
  if (node.plhandler && node.plhandler.length > 0) {
8169
8137
  output.push('HANDLER');
@@ -8199,7 +8167,7 @@ class Deparser {
8199
8167
  }
8200
8168
  output.push('LANGUAGE');
8201
8169
  if (node.lang) {
8202
- output.push(quote_utils_1.QuoteUtils.quote(node.lang));
8170
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.lang));
8203
8171
  }
8204
8172
  output.push('(');
8205
8173
  const transforms = [];
@@ -8227,7 +8195,7 @@ class Deparser {
8227
8195
  }
8228
8196
  output.push('TRIGGER');
8229
8197
  if (node.trigname) {
8230
- output.push(quote_utils_1.QuoteUtils.quote(node.trigname));
8198
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.trigname));
8231
8199
  }
8232
8200
  if (context.isPretty()) {
8233
8201
  const components = [];
@@ -8391,14 +8359,14 @@ class Deparser {
8391
8359
  output.push('OLD TABLE AS');
8392
8360
  }
8393
8361
  if (node.name) {
8394
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
8362
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
8395
8363
  }
8396
8364
  return output.join(' ');
8397
8365
  }
8398
8366
  CreateEventTrigStmt(node, context) {
8399
8367
  const output = ['CREATE EVENT TRIGGER'];
8400
8368
  if (node.trigname) {
8401
- output.push(quote_utils_1.QuoteUtils.quote(node.trigname));
8369
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.trigname));
8402
8370
  }
8403
8371
  output.push('ON');
8404
8372
  if (node.eventname) {
@@ -8424,7 +8392,7 @@ class Deparser {
8424
8392
  AlterEventTrigStmt(node, context) {
8425
8393
  const output = ['ALTER EVENT TRIGGER'];
8426
8394
  if (node.trigname) {
8427
- output.push(quote_utils_1.QuoteUtils.quote(node.trigname));
8395
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.trigname));
8428
8396
  }
8429
8397
  if (node.tgenabled) {
8430
8398
  switch (node.tgenabled) {
@@ -8559,11 +8527,11 @@ class Deparser {
8559
8527
  }
8560
8528
  output.push('ALL', 'IN', 'TABLESPACE');
8561
8529
  if (node.orig_tablespacename) {
8562
- output.push(quote_utils_1.QuoteUtils.quote(node.orig_tablespacename));
8530
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.orig_tablespacename));
8563
8531
  }
8564
8532
  output.push('SET', 'TABLESPACE');
8565
8533
  if (node.new_tablespacename) {
8566
- output.push(quote_utils_1.QuoteUtils.quote(node.new_tablespacename));
8534
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.new_tablespacename));
8567
8535
  }
8568
8536
  if (node.nowait) {
8569
8537
  output.push('NOWAIT');
@@ -8587,10 +8555,10 @@ class Deparser {
8587
8555
  const sequenceName = [];
8588
8556
  const seq = node.sequence;
8589
8557
  if (seq.schemaname) {
8590
- sequenceName.push(quote_utils_1.QuoteUtils.quote(seq.schemaname));
8558
+ sequenceName.push(quote_utils_1.QuoteUtils.quoteIdentifier(seq.schemaname));
8591
8559
  }
8592
8560
  if (seq.relname) {
8593
- sequenceName.push(quote_utils_1.QuoteUtils.quote(seq.relname));
8561
+ sequenceName.push(quote_utils_1.QuoteUtils.quoteIdentifier(seq.relname));
8594
8562
  }
8595
8563
  output.push(sequenceName.join('.'));
8596
8564
  }
@@ -8624,10 +8592,10 @@ class Deparser {
8624
8592
  const sequenceName = [];
8625
8593
  const seq = node.sequence;
8626
8594
  if (seq.schemaname) {
8627
- sequenceName.push(quote_utils_1.QuoteUtils.quote(seq.schemaname));
8595
+ sequenceName.push(quote_utils_1.QuoteUtils.quoteIdentifier(seq.schemaname));
8628
8596
  }
8629
8597
  if (seq.relname) {
8630
- sequenceName.push(quote_utils_1.QuoteUtils.quote(seq.relname));
8598
+ sequenceName.push(quote_utils_1.QuoteUtils.quoteIdentifier(seq.relname));
8631
8599
  }
8632
8600
  output.push(sequenceName.join('.'));
8633
8601
  }
@@ -8974,7 +8942,7 @@ class Deparser {
8974
8942
  }
8975
8943
  aliasname(node, context) {
8976
8944
  if (typeof node === 'string') {
8977
- return quote_utils_1.QuoteUtils.quote(node);
8945
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node);
8978
8946
  }
8979
8947
  return this.visit(node, context);
8980
8948
  }
@@ -9006,13 +8974,8 @@ class Deparser {
9006
8974
  const defName = defElem.defname;
9007
8975
  const defValue = defElem.arg;
9008
8976
  if (defName && defValue) {
9009
- let preservedDefName;
9010
- if (Deparser.needsQuotes(defName)) {
9011
- preservedDefName = `"${defName}"`;
9012
- }
9013
- else {
9014
- preservedDefName = this.preserveOperatorDefElemCase(defName);
9015
- }
8977
+ const quotedDefName = quote_utils_1.QuoteUtils.quoteIdentifier(defName);
8978
+ const preservedDefName = quotedDefName !== defName ? quotedDefName : this.preserveOperatorDefElemCase(defName);
9016
8979
  if ((defName.toLowerCase() === 'commutator' || defName.toLowerCase() === 'negator') && defValue.List) {
9017
8980
  const listItems = list_utils_1.ListUtils.unwrapList(defValue.List.items);
9018
8981
  if (listItems.length === 1 && listItems[0].String) {
@@ -9028,7 +8991,7 @@ class Deparser {
9028
8991
  else if (defName && !defValue) {
9029
8992
  // Handle boolean flags like HASHES, MERGES - preserve original case
9030
8993
  if (defName === 'Hashes' || defName === 'Merges') {
9031
- return `"${defName}"`;
8994
+ return quote_utils_1.QuoteUtils.quoteIdentifier(defName);
9032
8995
  }
9033
8996
  return this.preserveOperatorDefElemCase(defName).toUpperCase();
9034
8997
  }
@@ -9167,13 +9130,8 @@ class Deparser {
9167
9130
  const defName = defElem.defname;
9168
9131
  const defValue = defElem.arg;
9169
9132
  if (defName && defValue) {
9170
- let preservedDefName;
9171
- if (Deparser.needsQuotes(defName)) {
9172
- preservedDefName = `"${defName}"`;
9173
- }
9174
- else {
9175
- preservedDefName = defName;
9176
- }
9133
+ const quotedDefName = quote_utils_1.QuoteUtils.quoteIdentifier(defName);
9134
+ const preservedDefName = quotedDefName !== defName ? quotedDefName : defName;
9177
9135
  // Handle String arguments with single quotes for string literals
9178
9136
  if (defValue.String) {
9179
9137
  return `${preservedDefName} = '${defValue.String.sval}'`;
@@ -9328,7 +9286,7 @@ class Deparser {
9328
9286
  AlterDatabaseStmt(node, context) {
9329
9287
  const output = ['ALTER', 'DATABASE'];
9330
9288
  if (node.dbname) {
9331
- output.push(quote_utils_1.QuoteUtils.quote(node.dbname));
9289
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.dbname));
9332
9290
  }
9333
9291
  if (node.options && node.options.length > 0) {
9334
9292
  const options = list_utils_1.ListUtils.unwrapList(node.options).map(opt => this.visit(opt, context));
@@ -9339,7 +9297,7 @@ class Deparser {
9339
9297
  AlterDatabaseRefreshCollStmt(node, context) {
9340
9298
  const output = ['ALTER', 'DATABASE'];
9341
9299
  if (node.dbname) {
9342
- output.push(quote_utils_1.QuoteUtils.quote(node.dbname));
9300
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.dbname));
9343
9301
  }
9344
9302
  output.push('REFRESH', 'COLLATION', 'VERSION');
9345
9303
  return output.join(' ');
@@ -9347,7 +9305,7 @@ class Deparser {
9347
9305
  AlterDatabaseSetStmt(node, context) {
9348
9306
  const output = ['ALTER', 'DATABASE'];
9349
9307
  if (node.dbname) {
9350
- output.push(quote_utils_1.QuoteUtils.quote(node.dbname));
9308
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.dbname));
9351
9309
  }
9352
9310
  if (node.setstmt) {
9353
9311
  const setClause = this.VariableSetStmt(node.setstmt, context);
@@ -9358,7 +9316,7 @@ class Deparser {
9358
9316
  DeclareCursorStmt(node, context) {
9359
9317
  const output = ['DECLARE'];
9360
9318
  if (node.portalname) {
9361
- output.push(quote_utils_1.QuoteUtils.quote(node.portalname));
9319
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.portalname));
9362
9320
  }
9363
9321
  // Handle cursor options before CURSOR keyword
9364
9322
  const cursorOptions = [];
@@ -9400,7 +9358,7 @@ class Deparser {
9400
9358
  else if (node.pubobjtype === 'PUBLICATIONOBJ_TABLES_IN_SCHEMA') {
9401
9359
  output.push('TABLES IN SCHEMA');
9402
9360
  if (node.name) {
9403
- output.push(quote_utils_1.QuoteUtils.quote(node.name));
9361
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.name));
9404
9362
  }
9405
9363
  }
9406
9364
  else if (node.pubobjtype === 'PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA') {
@@ -9426,7 +9384,7 @@ class Deparser {
9426
9384
  CreateAmStmt(node, context) {
9427
9385
  const output = ['CREATE', 'ACCESS', 'METHOD'];
9428
9386
  if (node.amname) {
9429
- output.push(quote_utils_1.QuoteUtils.quote(node.amname));
9387
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.amname));
9430
9388
  }
9431
9389
  output.push('TYPE');
9432
9390
  switch (node.amtype) {
@@ -9486,7 +9444,7 @@ class Deparser {
9486
9444
  }
9487
9445
  }
9488
9446
  if (node.tableSpaceName) {
9489
- output.push('TABLESPACE', quote_utils_1.QuoteUtils.quote(node.tableSpaceName));
9447
+ output.push('TABLESPACE', quote_utils_1.QuoteUtils.quoteIdentifier(node.tableSpaceName));
9490
9448
  }
9491
9449
  return output.join(' ');
9492
9450
  }
@@ -9644,7 +9602,7 @@ class Deparser {
9644
9602
  RangeTableFuncCol(node, context) {
9645
9603
  const output = [];
9646
9604
  if (node.colname) {
9647
- output.push(quote_utils_1.QuoteUtils.quote(node.colname));
9605
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.colname));
9648
9606
  }
9649
9607
  if (node.for_ordinality) {
9650
9608
  output.push('FOR ORDINALITY');
@@ -9790,10 +9748,10 @@ class Deparser {
9790
9748
  if (node.op === 'IS_XMLPI') {
9791
9749
  if (node.name && node.args && node.args.length > 0) {
9792
9750
  const argStrs = list_utils_1.ListUtils.unwrapList(node.args).map(arg => this.visit(arg, context));
9793
- return `xmlpi(name ${quote_utils_1.QuoteUtils.quote(node.name)}, ${argStrs.join(', ')})`;
9751
+ return `xmlpi(name ${quote_utils_1.QuoteUtils.quoteIdentifier(node.name)}, ${argStrs.join(', ')})`;
9794
9752
  }
9795
9753
  else if (node.name) {
9796
- return `xmlpi(name ${quote_utils_1.QuoteUtils.quote(node.name)})`;
9754
+ return `xmlpi(name ${quote_utils_1.QuoteUtils.quoteIdentifier(node.name)})`;
9797
9755
  }
9798
9756
  else {
9799
9757
  return 'XMLPI()';
@@ -9808,7 +9766,7 @@ class Deparser {
9808
9766
  output.push('XMLELEMENT');
9809
9767
  const elementParts = [];
9810
9768
  if (node.name) {
9811
- elementParts.push(`NAME ${quote_utils_1.QuoteUtils.quote(node.name)}`);
9769
+ elementParts.push(`NAME ${quote_utils_1.QuoteUtils.quoteIdentifier(node.name)}`);
9812
9770
  }
9813
9771
  if (node.named_args && node.named_args.length > 0) {
9814
9772
  const namedArgStrs = list_utils_1.ListUtils.unwrapList(node.named_args).map(arg => this.visit(arg, context));
@@ -9908,7 +9866,7 @@ class Deparser {
9908
9866
  // Handle name and args for operations that don't have special handling
9909
9867
  if (node.op !== 'IS_XMLELEMENT' && node.op !== 'IS_XMLPARSE' && node.op !== 'IS_XMLROOT' && node.op !== 'IS_DOCUMENT') {
9910
9868
  if (node.name) {
9911
- const quotedName = quote_utils_1.QuoteUtils.quote(node.name);
9869
+ const quotedName = quote_utils_1.QuoteUtils.quoteIdentifier(node.name);
9912
9870
  output.push(`NAME ${quotedName}`);
9913
9871
  }
9914
9872
  if (node.args && node.args.length > 0) {
@@ -9929,26 +9887,26 @@ class Deparser {
9929
9887
  }
9930
9888
  schemaname(node, context) {
9931
9889
  if (typeof node === 'string') {
9932
- return quote_utils_1.QuoteUtils.quote(node);
9890
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node);
9933
9891
  }
9934
9892
  if (node && node.String && node.String.sval) {
9935
- return quote_utils_1.QuoteUtils.quote(node.String.sval);
9893
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.String.sval);
9936
9894
  }
9937
9895
  // Handle other node types without recursion
9938
9896
  if (node && typeof node === 'object') {
9939
9897
  if (node.sval !== undefined) {
9940
- return quote_utils_1.QuoteUtils.quote(node.sval);
9898
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.sval);
9941
9899
  }
9942
9900
  // Handle List nodes that might contain schema names
9943
9901
  if (node.List && Array.isArray(node.List.items)) {
9944
9902
  const items = node.List.items;
9945
9903
  if (items.length > 0 && items[0].String && items[0].String.sval) {
9946
- return quote_utils_1.QuoteUtils.quote(items[0].String.sval);
9904
+ return quote_utils_1.QuoteUtils.quoteIdentifier(items[0].String.sval);
9947
9905
  }
9948
9906
  }
9949
9907
  // For other complex nodes, try to extract string value without recursion
9950
9908
  if (node.val !== undefined) {
9951
- return quote_utils_1.QuoteUtils.quote(node.val);
9909
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.val);
9952
9910
  }
9953
9911
  return '';
9954
9912
  }
@@ -10011,7 +9969,7 @@ class Deparser {
10011
9969
  }
10012
9970
  output.push('RULE');
10013
9971
  if (node.rulename) {
10014
- output.push(quote_utils_1.QuoteUtils.quote(node.rulename));
9972
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.rulename));
10015
9973
  }
10016
9974
  output.push('AS ON');
10017
9975
  if (node.event) {
@@ -10078,42 +10036,42 @@ class Deparser {
10078
10036
  }
10079
10037
  relname(node, context) {
10080
10038
  if (typeof node === 'string') {
10081
- return quote_utils_1.QuoteUtils.quote(node);
10039
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node);
10082
10040
  }
10083
10041
  if (node && node.String && node.String.sval) {
10084
- return quote_utils_1.QuoteUtils.quote(node.String.sval);
10042
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.String.sval);
10085
10043
  }
10086
10044
  if (node && typeof node === 'object' && node.relname) {
10087
- return quote_utils_1.QuoteUtils.quote(node.relname);
10045
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.relname);
10088
10046
  }
10089
10047
  return this.visit(node, context);
10090
10048
  }
10091
10049
  rel(node, context) {
10092
10050
  if (typeof node === 'string') {
10093
- return quote_utils_1.QuoteUtils.quote(node);
10051
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node);
10094
10052
  }
10095
10053
  if (node && node.String && node.String.sval) {
10096
- return quote_utils_1.QuoteUtils.quote(node.String.sval);
10054
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.String.sval);
10097
10055
  }
10098
10056
  if (node && node.RangeVar) {
10099
10057
  return this.RangeVar(node.RangeVar, context);
10100
10058
  }
10101
10059
  if (node && typeof node === 'object' && node.relname) {
10102
- return quote_utils_1.QuoteUtils.quote(node.relname);
10060
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.relname);
10103
10061
  }
10104
10062
  return this.visit(node, context);
10105
10063
  }
10106
10064
  objname(node, context) {
10107
10065
  if (typeof node === 'string') {
10108
- return quote_utils_1.QuoteUtils.quote(node);
10066
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node);
10109
10067
  }
10110
10068
  if (node && node.String && node.String.sval) {
10111
- return quote_utils_1.QuoteUtils.quote(node.String.sval);
10069
+ return quote_utils_1.QuoteUtils.quoteIdentifier(node.String.sval);
10112
10070
  }
10113
10071
  if (Array.isArray(node)) {
10114
10072
  const parts = node.map(part => {
10115
10073
  if (part && part.String && part.String.sval) {
10116
- return quote_utils_1.QuoteUtils.quote(part.String.sval);
10074
+ return quote_utils_1.QuoteUtils.quoteIdentifier(part.String.sval);
10117
10075
  }
10118
10076
  return this.visit(part, context);
10119
10077
  });
@@ -10184,7 +10142,7 @@ class Deparser {
10184
10142
  CurrentOfExpr(node, context) {
10185
10143
  const output = ['CURRENT OF'];
10186
10144
  if (node.cursor_name) {
10187
- output.push(quote_utils_1.QuoteUtils.quote(node.cursor_name));
10145
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.cursor_name));
10188
10146
  }
10189
10147
  if (node.cursor_param > 0) {
10190
10148
  output.push(`$${node.cursor_param}`);
@@ -10267,7 +10225,7 @@ class Deparser {
10267
10225
  if (items.length === 2) {
10268
10226
  const schemaName = items[0].String?.sval || '';
10269
10227
  const domainName = items[1].String?.sval || '';
10270
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(domainName)}`);
10228
+ output.push(quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, domainName));
10271
10229
  }
10272
10230
  else {
10273
10231
  output.push(this.visit(node.object, context));
@@ -10279,7 +10237,7 @@ class Deparser {
10279
10237
  if (items.length === 2) {
10280
10238
  const schemaName = items[0].String?.sval || '';
10281
10239
  const typeName = items[1].String?.sval || '';
10282
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(typeName)}`);
10240
+ output.push(quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, typeName));
10283
10241
  }
10284
10242
  else {
10285
10243
  output.push(this.visit(node.object, context));
@@ -10291,7 +10249,7 @@ class Deparser {
10291
10249
  if (items.length === 2) {
10292
10250
  const schemaName = items[0].String?.sval || '';
10293
10251
  const conversionName = items[1].String?.sval || '';
10294
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(conversionName)}`);
10252
+ output.push(quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, conversionName));
10295
10253
  }
10296
10254
  else {
10297
10255
  output.push(this.visit(node.object, context));
@@ -10303,7 +10261,7 @@ class Deparser {
10303
10261
  if (items.length === 2) {
10304
10262
  const schemaName = items[0].String?.sval || '';
10305
10263
  const parserName = items[1].String?.sval || '';
10306
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(parserName)}`);
10264
+ output.push(quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, parserName));
10307
10265
  }
10308
10266
  else {
10309
10267
  output.push(this.visit(node.object, context));
@@ -10315,7 +10273,7 @@ class Deparser {
10315
10273
  if (items.length === 2) {
10316
10274
  const schemaName = items[0].String?.sval || '';
10317
10275
  const configName = items[1].String?.sval || '';
10318
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(configName)}`);
10276
+ output.push(quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, configName));
10319
10277
  }
10320
10278
  else {
10321
10279
  output.push(this.visit(node.object, context));
@@ -10327,7 +10285,7 @@ class Deparser {
10327
10285
  if (items.length === 2) {
10328
10286
  const schemaName = items[0].String?.sval || '';
10329
10287
  const templateName = items[1].String?.sval || '';
10330
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(templateName)}`);
10288
+ output.push(quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, templateName));
10331
10289
  }
10332
10290
  else {
10333
10291
  output.push(this.visit(node.object, context));
@@ -10339,7 +10297,7 @@ class Deparser {
10339
10297
  if (items.length === 2) {
10340
10298
  const schemaName = items[0].String?.sval || '';
10341
10299
  const dictionaryName = items[1].String?.sval || '';
10342
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(dictionaryName)}`);
10300
+ output.push(quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, dictionaryName));
10343
10301
  }
10344
10302
  else {
10345
10303
  output.push(this.visit(node.object, context));
@@ -10351,13 +10309,13 @@ class Deparser {
10351
10309
  if (items.length === 2) {
10352
10310
  const accessMethod = items[0].String?.sval || '';
10353
10311
  const opClassName = items[1].String?.sval || '';
10354
- output.push(`${quote_utils_1.QuoteUtils.quote(opClassName)} USING ${accessMethod}`);
10312
+ output.push(`${quote_utils_1.QuoteUtils.quoteIdentifier(opClassName)} USING ${accessMethod}`);
10355
10313
  }
10356
10314
  else if (items.length === 3) {
10357
10315
  const accessMethod = items[0].String?.sval || '';
10358
10316
  const schemaName = items[1].String?.sval || '';
10359
10317
  const opClassName = items[2].String?.sval || '';
10360
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(opClassName)} USING ${accessMethod}`);
10318
+ output.push(`${quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, opClassName)} USING ${accessMethod}`);
10361
10319
  }
10362
10320
  else {
10363
10321
  output.push(this.visit(node.object, context));
@@ -10369,13 +10327,13 @@ class Deparser {
10369
10327
  if (items.length === 2) {
10370
10328
  const accessMethod = items[0].String?.sval || '';
10371
10329
  const opFamilyName = items[1].String?.sval || '';
10372
- output.push(`${quote_utils_1.QuoteUtils.quote(opFamilyName)} USING ${accessMethod}`);
10330
+ output.push(`${quote_utils_1.QuoteUtils.quoteIdentifier(opFamilyName)} USING ${accessMethod}`);
10373
10331
  }
10374
10332
  else if (items.length === 3) {
10375
10333
  const accessMethod = items[0].String?.sval || '';
10376
10334
  const schemaName = items[1].String?.sval || '';
10377
10335
  const opFamilyName = items[2].String?.sval || '';
10378
- output.push(`${quote_utils_1.QuoteUtils.quote(schemaName)}.${quote_utils_1.QuoteUtils.quote(opFamilyName)} USING ${accessMethod}`);
10336
+ output.push(`${quote_utils_1.QuoteUtils.quoteQualifiedIdentifier(schemaName, opFamilyName)} USING ${accessMethod}`);
10379
10337
  }
10380
10338
  else {
10381
10339
  output.push(this.visit(node.object, context));
@@ -10387,7 +10345,7 @@ class Deparser {
10387
10345
  }
10388
10346
  output.push('SET SCHEMA');
10389
10347
  if (node.newschema) {
10390
- output.push(quote_utils_1.QuoteUtils.quote(node.newschema));
10348
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.newschema));
10391
10349
  }
10392
10350
  return output.join(' ');
10393
10351
  }
@@ -10456,7 +10414,7 @@ class Deparser {
10456
10414
  }
10457
10415
  if (node.servername) {
10458
10416
  output.push('SERVER');
10459
- output.push(quote_utils_1.QuoteUtils.quote(node.servername));
10417
+ output.push(quote_utils_1.QuoteUtils.quoteIdentifier(node.servername));
10460
10418
  }
10461
10419
  if (node.options && node.options.length > 0) {
10462
10420
  const foreignTableContext = context.spawn('CreateForeignTableStmt');