Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -5294,10 +5294,10 @@ cast_expr
}]
};
}
/ LPAREN __ e:(or_expr / column_ref_array_index / param) __ RPAREN __ c:cast_double_colon? {
/ LPAREN __ e:(or_expr / column_ref_array_index / var_decl / param) __ RPAREN __ c:cast_double_colon? {
/* => {
type: 'cast';
expr: or_expr | column_ref | param
expr: or_expr | column_ref | var_decl | param
| expr;
keyword: 'cast';
} & cast_double_colon
Expand All @@ -5311,10 +5311,10 @@ cast_expr
expr: e,
}
}
/ e:(interval_expr / aggr_func / window_func / func_call / column_ref_quoted / literal / case_expr / column_ref_array_index / param) __ c:cast_double_colon? {
/ e:(interval_expr / aggr_func / window_func / func_call / column_ref_quoted / literal / case_expr / column_ref_array_index / var_decl / param) __ c:cast_double_colon? {
/* => ({
type: 'cast';
expr: literal | jsonb_expr | aggr_func | func_call | case_expr | interval_expr | column_ref | param
expr: literal | jsonb_expr | aggr_func | func_call | case_expr | interval_expr | column_ref | var_decl | param
| expr;
keyword: 'cast';
} & cast_double_colon)
Expand Down
31 changes: 31 additions & 0 deletions test/postgres.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,37 @@ describe('Postgres', () => {
'CREATE TABLE "test_table" (id INT NOT NULL, vector TSVECTOR)'
]
},
{
title: 'cast on dollar parameter placeholder inside a function argument',
sql: [
`SELECT jsonb_array_elements_text($1::jsonb)`,
`SELECT jsonb_array_elements_text($1::JSONB)`
]
},
{
title: 'cast on parameter placeholder in WHERE clause',
sql: [
`SELECT * FROM "t" WHERE a = $1::jsonb`,
`SELECT * FROM "t" WHERE a = $1::JSONB`
]
},
{
title: 'cast on parenthesized parameter placeholder',
sql: [
`SELECT ($1)::int`,
`SELECT $1::INT`
]
},
{
title: 'cast on parameter placeholder with nested function casts in CTE',
sql: [
`WITH input_deals AS (
SELECT (jsonb_array_elements_text($1::jsonb))::int AS deal_no
)
SELECT * FROM input_deals`,
`WITH "input_deals" AS (SELECT (jsonb_array_elements_text($1::JSONB))::INT AS "deal_no") SELECT * FROM "input_deals"`
]
},
]
function neatlyNestTestedSQL(sqlList){
sqlList.forEach(sqlInfo => {
Expand Down