Skip to content

Commit 0ccc2f5

Browse files
Merge pull request #1712 from taozhi8833998/fix-crosstab-pg
fix: crosstab in pg
2 parents 75dcf8f + 210f445 commit 0ccc2f5

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pegjs/postgresql.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,15 +4312,15 @@ trim_func_clause
43124312
}
43134313

43144314
tablefunc_clause
4315-
= 'crosstab'i __ LPAREN __ s:literal_list __ RPAREN __ KW_AS __ 'final_result' LPAREN __ cds:column_data_type_list __ RPAREN {
4315+
= 'crosstab'i __ LPAREN __ s:expr_list __ RPAREN __ KW_AS __ n:ident_name __ LPAREN __ cds:column_data_type_list __ RPAREN {
43164316
// => { type: 'tablefunc'; name: crosstab; args: expr_list; as: func_call }
43174317
return {
43184318
type: 'tablefunc',
43194319
name: 'crosstab',
4320-
args: { type: 'expr_list', value: s },
4320+
args: s,
43214321
as: {
43224322
type: 'function',
4323-
name: 'final_result',
4323+
name: n,
43244324
args: { type: 'expr_list', value: cds.map(v => ({ ...v, type: 'column_definition' })) },
43254325
}
43264326
}

test/postgres.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,8 @@ describe('Postgres', () => {
15821582
{
15831583
title: 'crosstab tablefunc',
15841584
sql: [
1585-
`SELECT * FROM crosstab( 'select student, subject, evaluation_result from evaluations order by 1,2') AS final_result(Student TEXT, Geography NUMERIC,History NUMERIC,Language NUMERIC,Maths NUMERIC,Music NUMERIC);`,
1586-
`SELECT * FROM crosstab('select student, subject, evaluation_result from evaluations order by 1,2') AS final_result("Student" TEXT, "Geography" NUMERIC, "History" NUMERIC, "Language" NUMERIC, "Maths" NUMERIC, "Music" NUMERIC)`
1585+
`SELECT * FROM crosstab( 'select student, subject, evaluation_result from evaluations order by 1,2', $$VALUES ('t'::text), ('f'::text)$$) AS final_result(Student TEXT, Geography NUMERIC,History NUMERIC,Language NUMERIC,Maths NUMERIC,Music NUMERIC);`,
1586+
`SELECT * FROM crosstab('select student, subject, evaluation_result from evaluations order by 1,2', $$VALUES ('t'::text), ('f'::text)$$) AS final_result("Student" TEXT, "Geography" NUMERIC, "History" NUMERIC, "Language" NUMERIC, "Maths" NUMERIC, "Music" NUMERIC)`
15871587
]
15881588
},
15891589
]

0 commit comments

Comments
 (0)