From b5fd4e1b167731d6ca1b7285ee8f83a410441648 Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Sun, 24 Dec 2023 21:39:30 +0800 Subject: [PATCH] fix: case when then expr with additive in pg --- pegjs/postgresql.pegjs | 4 ++-- test/postgres.spec.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pegjs/postgresql.pegjs b/pegjs/postgresql.pegjs index 9a4adc2e..8c86224d 100644 --- a/pegjs/postgresql.pegjs +++ b/pegjs/postgresql.pegjs @@ -4501,10 +4501,10 @@ cast_expr } }; } - / LPAREN __ e:(literal / aggr_func / window_func / func_call / case_expr / interval_expr / column_ref_array_index / param) __ RPAREN __ c:cast_double_colon? { + / LPAREN __ e:(or_expr / column_ref_array_index / param) __ RPAREN __ c:cast_double_colon? { /* => { type: 'cast'; - expr: literal | aggr_func | func_call | case_expr | interval_expr | column_ref | param + expr: or_expr | column_ref | param | expr; keyword: 'cast'; ...cast_double_colon; diff --git a/test/postgres.spec.js b/test/postgres.spec.js index f5bd4d6a..629c6ab4 100644 --- a/test/postgres.spec.js +++ b/test/postgres.spec.js @@ -1593,6 +1593,17 @@ describe('Postgres', () => { `SELECT * FROM "test" WHERE "théâtre" = 'Molière'` ] }, + { + title: 'cast when expr is additive_ expr', + sql: [ + `SELECT + CASE + WHEN updated IS NOT NULL THEN (updated - created)::TIME + END AS some_time + FROM some_table`, + 'SELECT CASE WHEN "updated" IS NOT NULL THEN ("updated" - "created")::TIME END AS "some_time" FROM "some_table"' + ] + }, ] neatlyNestTestedSQL(SQL_LIST) })