Skip to content

Commit bf10ae1

Browse files
committed
Allow the use of parenthesis in CREATE TABLE AS (...)
1 parent 16f511e commit bf10ae1

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

doc/sql.extensions/README.create_table_as_query.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tables may be created from a query result using the following syntax:
55
```sql
66
CREATE [{GLOBAL | LOCAL} TEMPORARY] TABLE [IF NOT EXISTS] <table name>
77
[ (<column name> [, <column name> ...]) ]
8-
AS <query expression>
8+
AS { (<query expression>) | <query expression> }
99
[WITH [NO] DATA]
1010
[ON COMMIT {DELETE | PRESERVE} ROWS]
1111
```
@@ -67,6 +67,12 @@ CREATE LOCAL TEMPORARY TABLE tx_work AS
6767
SELECT emp_no, salary
6868
FROM employee
6969
WITH NO DATA;
70+
71+
CREATE TABLE high_salary AS
72+
(WITH avg_salary AS (SELECT AVG(salary) AS avg_salary FROM employee)
73+
SELECT e.emp_no, e.salary
74+
FROM employee e, avg_salary a
75+
WHERE e.salary > a.avg_salary);
7076
```
7177

7278
## ISQL behavior

src/dsql/parse-conflicts.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
152 shift/reduce conflicts, 7 reduce/reduce conflicts.
1+
153 shift/reduce conflicts, 7 reduce/reduce conflicts.

src/dsql/parse.y

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,15 @@ table_as_query_clause
24412441
node->withData = $5;
24422442
$$ = node;
24432443
}
2444+
| simple_table_name column_parens_opt AS '(' select_expr ')' with_data_opt
2445+
{
2446+
const auto node = newNode<CreateRelationNode>($1);
2447+
node->queryColumns = $2;
2448+
node->querySelectExpr = $5;
2449+
node->querySource = makeParseStr(YYPOSNARG(5), YYPOSNARG(5));
2450+
node->withData = $7;
2451+
$$ = node;
2452+
}
24442453
;
24452454

24462455
%type <createRelationNode> table_clause

0 commit comments

Comments
 (0)