pgsql-deparser 17.18.2 → 17.18.4

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
@@ -1317,8 +1317,13 @@ class Deparser {
1317
1317
  }
1318
1318
  // Handle EXTRACT function with SQL syntax
1319
1319
  if (node.funcformat === 'COERCE_SQL_SYNTAX' && name === 'pg_catalog.extract' && args.length >= 2) {
1320
- const field = this.visit(args[0], context);
1320
+ let field = this.visit(args[0], context);
1321
1321
  const source = this.visit(args[1], context);
1322
+ // EXTRACT requires an unquoted uppercase keyword (EPOCH, YEAR, etc.)
1323
+ // but A_Const sval deparsing wraps it in single quotes — strip and uppercase
1324
+ if (field.startsWith("'") && field.endsWith("'")) {
1325
+ field = field.slice(1, -1).toUpperCase();
1326
+ }
1322
1327
  return `EXTRACT(${field} FROM ${source})`;
1323
1328
  }
1324
1329
  // Handle TRIM function with SQL syntax (TRIM TRAILING/LEADING/BOTH)
@@ -5003,7 +5008,8 @@ class Deparser {
5003
5008
  }
5004
5009
  output.push('SET EXPRESSION');
5005
5010
  if (node.def) {
5006
- output.push(this.visit(node.def, context));
5011
+ output.push('AS');
5012
+ output.push(context.parens(this.visit(node.def, context)));
5007
5013
  }
5008
5014
  break;
5009
5015
  case 'AT_DropExpression':
@@ -5012,6 +5018,9 @@ class Deparser {
5012
5018
  output.push(quotes_1.QuoteUtils.quoteIdentifier(node.name));
5013
5019
  }
5014
5020
  output.push('DROP EXPRESSION');
5021
+ if (node.missing_ok) {
5022
+ output.push('IF EXISTS');
5023
+ }
5015
5024
  break;
5016
5025
  case 'AT_CheckNotNull':
5017
5026
  output.push('ALTER COLUMN');
package/esm/deparser.js CHANGED
@@ -1314,8 +1314,13 @@ export class Deparser {
1314
1314
  }
1315
1315
  // Handle EXTRACT function with SQL syntax
1316
1316
  if (node.funcformat === 'COERCE_SQL_SYNTAX' && name === 'pg_catalog.extract' && args.length >= 2) {
1317
- const field = this.visit(args[0], context);
1317
+ let field = this.visit(args[0], context);
1318
1318
  const source = this.visit(args[1], context);
1319
+ // EXTRACT requires an unquoted uppercase keyword (EPOCH, YEAR, etc.)
1320
+ // but A_Const sval deparsing wraps it in single quotes — strip and uppercase
1321
+ if (field.startsWith("'") && field.endsWith("'")) {
1322
+ field = field.slice(1, -1).toUpperCase();
1323
+ }
1319
1324
  return `EXTRACT(${field} FROM ${source})`;
1320
1325
  }
1321
1326
  // Handle TRIM function with SQL syntax (TRIM TRAILING/LEADING/BOTH)
@@ -5000,7 +5005,8 @@ export class Deparser {
5000
5005
  }
5001
5006
  output.push('SET EXPRESSION');
5002
5007
  if (node.def) {
5003
- output.push(this.visit(node.def, context));
5008
+ output.push('AS');
5009
+ output.push(context.parens(this.visit(node.def, context)));
5004
5010
  }
5005
5011
  break;
5006
5012
  case 'AT_DropExpression':
@@ -5009,6 +5015,9 @@ export class Deparser {
5009
5015
  output.push(QuoteUtils.quoteIdentifier(node.name));
5010
5016
  }
5011
5017
  output.push('DROP EXPRESSION');
5018
+ if (node.missing_ok) {
5019
+ output.push('IF EXISTS');
5020
+ }
5012
5021
  break;
5013
5022
  case 'AT_CheckNotNull':
5014
5023
  output.push('ALTER COLUMN');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-deparser",
3
- "version": "17.18.2",
3
+ "version": "17.18.4",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PostgreSQL AST Deparser",
6
6
  "main": "index.js",
@@ -60,5 +60,5 @@
60
60
  "@pgsql/quotes": "17.1.0",
61
61
  "@pgsql/types": "^17.6.2"
62
62
  },
63
- "gitHead": "cdd732b4694b84522895d2d1dd8d5db9944875d5"
63
+ "gitHead": "987c0c66fee20025b193cb497d1ceb8832dc4ed2"
64
64
  }