Skip to content

Commit 1f64b7d

Browse files
committed
fix: allow cast to type with column alias in postgres
1 parent a6aa69b commit 1f64b7d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pegjs/postgresql.pegjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5365,15 +5365,13 @@ cast_data_type
53655365
}
53665366

53675367
cast_double_colon
5368-
= s:(KW_DOUBLE_COLON __ cast_data_type)+ __ alias:alias_clause? {
5368+
= s:(KW_DOUBLE_COLON __ cast_data_type)+ {
53695369
/* => {
5370-
as?: alias_clause,
53715370
symbol: '::' | 'as',
53725371
target: cast_data_type[];
53735372
}
53745373
*/
53755374
return {
5376-
as: alias,
53775375
symbol: '::',
53785376
target: s.map(v => v[2]),
53795377
}

test/postgres.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,13 @@ describe('Postgres', () => {
19501950
'ALTER TABLE "table_name" REPLICA IDENTITY FULL',
19511951
]
19521952
},
1953+
{
1954+
title: 'cast without parentheses and with alias',
1955+
sql: [
1956+
'SELECT "createdAt"::date AS created_at, "updatedAt"::date "updated_at", count(*) as "value"',
1957+
'SELECT "createdAt"::DATE AS "created_at", "updatedAt"::DATE AS "updated_at", COUNT(*) AS "value"'
1958+
]
1959+
},
19531960
]
19541961
function neatlyNestTestedSQL(sqlList){
19551962
sqlList.forEach(sqlInfo => {

0 commit comments

Comments
 (0)