From a11d9c65b0c4687d914f30b11fdb165ab2296d85 Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Sat, 13 Jul 2024 10:23:53 +0800 Subject: [PATCH] fix: binary expr as fun args in pg --- src/expr.js | 1 + test/postgres.spec.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/expr.js b/src/expr.js index 74262878..ddd4c44d 100644 --- a/src/expr.js +++ b/src/expr.js @@ -82,6 +82,7 @@ function unaryToSQL(unarExpr) { function getExprListSQL(exprList) { if (!exprList) return [] + if (!Array.isArray(exprList)) exprList = [exprList] return exprList.map(exprToSQL) } diff --git a/test/postgres.spec.js b/test/postgres.spec.js index 3ff3779c..9fd00c45 100644 --- a/test/postgres.spec.js +++ b/test/postgres.spec.js @@ -1521,6 +1521,26 @@ describe('Postgres', () => { `CREATE TABLE "table_0" ("hi" INTEGER ARRAY) ; CREATE TABLE "table_1" ("hi" INTEGER[3])` ] }, + { + title: 'binary expr as fun args', + sql: [ + `SELECT + somefunc( + engineering_networks.realizaciya, + engineering_networks.company = 'blah-blah' + AND + engineering_networks.obem_realizacii_tip = 'uslugi' + ) AS var0, + If(var0 > 0, '2', '1') AS fontColor + FROM engineering_networks AS engineering_networks + WHERE + engineering_networks.company = 'blah-blah' AND + engineering_networks.month IN ('April') AND + engineering_networks.year IN ('2024') + LIMIT 1;`, + `SELECT somefunc("engineering_networks".realizaciya, "engineering_networks".company = 'blah-blah' AND "engineering_networks".obem_realizacii_tip = 'uslugi') AS "var0", If(var0 > 0, '2', '1') AS "fontColor" FROM "engineering_networks" AS "engineering_networks" WHERE "engineering_networks".company = 'blah-blah' AND "engineering_networks".month IN ('April') AND "engineering_networks".year IN ('2024') LIMIT 1` + ], + } ] function neatlyNestTestedSQL(sqlList){ sqlList.forEach(sqlInfo => {