Skip to content

Commit

Permalink
Merge pull request #1735 from taozhi8833998/fix-case-when-additive-pg
Browse files Browse the repository at this point in the history
fix: case when then expr with additive in pg
  • Loading branch information
taozhi8833998 authored Dec 24, 2023
2 parents 2571991 + b5fd4e1 commit a9344d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions test/postgres.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit a9344d2

Please sign in to comment.