File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -2289,7 +2289,7 @@ with_clause
22892289 }
22902290
22912291cte_definition
2292- = name :(literal_string / ident_name / table_name ) __ columns :cte_column_definition ? __ KW_AS __ LPAREN __ stmt :set_op_stmt __ RPAREN {
2292+ = name :(literal_string / ident_name / table_name ) __ columns :cte_column_definition ? __ KW_AS __ LPAREN __ stmt :( value_clause / set_op_stmt ) __ RPAREN {
22932293 if (typeof name === ' string' ) name = { type: ' default' , value: name }
22942294 if (name .table ) name = { type: ' default' , value: name .table }
22952295 return { name, stmt, columns };
Original file line number Diff line number Diff line change 11import { columnRefToSQL } from './column'
22import { exprToSQL } from './expr'
3- import { identifierToSql , literalToSQL } from './util'
3+ import { commonOptionConnector , identifierToSql , literalToSQL } from './util'
44
55/**
66 * @param {Array<Object> } withExpr
@@ -11,7 +11,8 @@ function withToSQL(withExpr) {
1111 const withExprStr = withExpr . map ( cte => {
1212 const { name, stmt, columns } = cte
1313 const column = Array . isArray ( columns ) ? `(${ columns . map ( columnRefToSQL ) . join ( ', ' ) } )` : ''
14- return `${ name . type === 'default' ? identifierToSql ( name . value ) : literalToSQL ( name ) } ${ column } AS (${ exprToSQL ( stmt ) } )`
14+ const expr = commonOptionConnector ( stmt . type === 'values' ? 'VALUES' : '' , exprToSQL , stmt )
15+ return `${ name . type === 'default' ? identifierToSql ( name . value ) : literalToSQL ( name ) } ${ column } AS (${ expr } )`
1516 } ) . join ( ', ' )
1617
1718 return `WITH ${ isRecursive } ${ withExprStr } `
Original file line number Diff line number Diff line change @@ -1326,6 +1326,13 @@ describe('mysql', () => {
13261326 "SELECT `crème` AS `brûlée` FROM `café` WHERE `âtre` = 'Molière'"
13271327 ]
13281328 } ,
1329+ {
1330+ title : 'with clause' ,
1331+ sql : [
1332+ "WITH T AS (VALUES ROW('foobar')) SELECT * FROM T" ,
1333+ "WITH `T` AS (VALUES ROW('foobar')) SELECT * FROM `T`"
1334+ ]
1335+ } ,
13291336 ]
13301337 SQL_LIST . forEach ( sqlInfo => {
13311338 const { title, sql } = sqlInfo
You can’t perform that action at this time.
0 commit comments