Skip to content

Commit 255ffb3

Browse files
authored
Merge pull request #104 from cvng/feat/create-table-3
test: add support for create table as
2 parents 92a8f2b + 7141a1b commit 255ffb3

File tree

4 files changed

+131
-48
lines changed

4 files changed

+131
-48
lines changed

crates/codegen/src/get_node_properties.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,10 @@ fn custom_handlers(node: &Node) -> TokenStream {
877877

878878
if names.len() == 2 && names[0] == "pg_catalog" {
879879
match names[1].as_str() {
880+
"float8" => {
881+
tokens.push(TokenProperty::from(Token::DoubleP));
882+
tokens.push(TokenProperty::from(Token::Precision));
883+
},
880884
"interval" => {
881885
// Adapted from https://github.com/postgres/postgres/blob/REL_15_STABLE/src/backend/utils/adt/timestamp.c#L1103
882886
const HOUR: i32 = 10;

crates/parser/tests/data/statements/valid/0043.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ CREATE TABLE types (a real, b double precision, c numeric(2, 3), d char(4), e ch
44
CREATE TABLE types (a geometry(point) NOT NULL);
55
CREATE TABLE tablename (colname int NOT NULL DEFAULT nextval('tablename_colname_seq'));
66
CREATE TABLE capitals (state char(2)) INHERITS (cities);
7-
/* TODO: CREATE TEMPORARY TABLE temp AS SELECT c FROM t; */ SELECT 1;
8-
/* TODO: CREATE TABLE films2 AS SELECT * FROM films; */ SELECT 1;
7+
CREATE TEMPORARY TABLE temp AS SELECT c FROM t;
8+
CREATE TABLE films2 AS SELECT * FROM films;
99
CREATE TEMPORARY TABLE films_recent ON COMMIT DROP AS SELECT * FROM films WHERE date_prod > $1;
1010
CREATE TABLE like_constraint_rename_cache (LIKE constraint_rename_cache INCLUDING ALL);
1111
CREATE TABLE distributors (did int, name varchar(40), UNIQUE (name) WITH (fillfactor=70)) WITH (fillfactor=70);

crates/parser/tests/snapshots/statements/valid/0043@7.snap

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
---
22
source: crates/parser/tests/statement_parser_test.rs
3-
description: "/* TODO: CREATE TEMPORARY TABLE temp AS SELECT c FROM t; */ SELECT 1;"
3+
description: CREATE TEMPORARY TABLE temp AS SELECT c FROM t;
44
---
55
Parse {
6-
cst: SourceFile@0..68
7-
CComment@0..59 "/* TODO: CREATE TEMPO ..."
8-
SelectStmt@59..68
9-
Select@59..65 "SELECT"
10-
Whitespace@65..66 " "
11-
ResTarget@66..67
12-
AConst@66..67
13-
Iconst@66..67 "1"
14-
Ascii59@67..68 ";"
6+
cst: SourceFile@0..46
7+
Create@0..6 "CREATE"
8+
Whitespace@6..7 " "
9+
Temporary@7..16 "TEMPORARY"
10+
Whitespace@16..17 " "
11+
Table@17..22 "TABLE"
12+
Whitespace@22..23 " "
13+
Temp@23..27 "temp"
14+
Whitespace@27..28 " "
15+
As@28..30 "AS"
16+
SelectStmt@30..46
17+
Select@30..36 "SELECT"
18+
Whitespace@36..37 " "
19+
ResTarget@37..38
20+
ColumnRef@37..38
21+
Ident@37..38 "c"
22+
Whitespace@38..39 " "
23+
From@39..43 "FROM"
24+
Whitespace@43..44 " "
25+
RangeVar@44..45
26+
Ident@44..45 "t"
27+
Ascii59@45..46 ";"
1528
,
16-
errors: [],
29+
errors: [
30+
SyntaxError(
31+
"Expected Ascii59, found Whitespace",
32+
30..30,
33+
),
34+
SyntaxError(
35+
"Invalid statement: syntax error at end of input",
36+
0..9,
37+
),
38+
],
1739
stmts: [
1840
RawStmt {
1941
stmt: SelectStmt(
@@ -30,17 +52,20 @@ Parse {
3052
val: Some(
3153
Node {
3254
node: Some(
33-
AConst(
34-
AConst {
35-
isnull: false,
55+
ColumnRef(
56+
ColumnRef {
57+
fields: [
58+
Node {
59+
node: Some(
60+
String(
61+
String {
62+
sval: "c",
63+
},
64+
),
65+
),
66+
},
67+
],
3668
location: 7,
37-
val: Some(
38-
Ival(
39-
Integer {
40-
ival: 1,
41-
},
42-
),
43-
),
4469
},
4570
),
4671
),
@@ -52,7 +77,23 @@ Parse {
5277
),
5378
},
5479
],
55-
from_clause: [],
80+
from_clause: [
81+
Node {
82+
node: Some(
83+
RangeVar(
84+
RangeVar {
85+
catalogname: "",
86+
schemaname: "",
87+
relname: "t",
88+
inh: true,
89+
relpersistence: "p",
90+
alias: None,
91+
location: 14,
92+
},
93+
),
94+
),
95+
},
96+
],
5697
where_clause: None,
5798
group_clause: [],
5899
group_distinct: false,
@@ -71,7 +112,7 @@ Parse {
71112
rarg: None,
72113
},
73114
),
74-
range: 59..68,
115+
range: 30..46,
75116
},
76117
],
77118
}

crates/parser/tests/snapshots/statements/valid/0043@8.snap

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
---
22
source: crates/parser/tests/statement_parser_test.rs
3-
description: "/* TODO: CREATE TABLE films2 AS SELECT * FROM films; */ SELECT 1;"
3+
description: CREATE TABLE films2 AS SELECT * FROM films;
44
---
55
Parse {
6-
cst: SourceFile@0..64
7-
CComment@0..55 "/* TODO: CREATE TABLE ..."
8-
SelectStmt@55..64
9-
Select@55..61 "SELECT"
10-
Whitespace@61..62 " "
11-
ResTarget@62..63
12-
AConst@62..63
13-
Iconst@62..63 "1"
14-
Ascii59@63..64 ";"
6+
cst: SourceFile@0..42
7+
Create@0..6 "CREATE"
8+
Whitespace@6..7 " "
9+
Table@7..12 "TABLE"
10+
Whitespace@12..13 " "
11+
Ident@13..19 "films2"
12+
Whitespace@19..20 " "
13+
As@20..22 "AS"
14+
SelectStmt@22..42
15+
Select@22..28 "SELECT"
16+
Whitespace@28..29 " "
17+
ResTarget@29..30
18+
ColumnRef@29..30
19+
AStar@29..30
20+
Ascii42@29..30 "*"
21+
Whitespace@30..31 " "
22+
From@31..35 "FROM"
23+
Whitespace@35..36 " "
24+
RangeVar@36..41
25+
Ident@36..41 "films"
26+
Ascii59@41..42 ";"
1527
,
16-
errors: [],
28+
errors: [
29+
SyntaxError(
30+
"Expected Ascii59, found Whitespace",
31+
22..22,
32+
),
33+
SyntaxError(
34+
"Invalid statement: syntax error at end of input",
35+
0..7,
36+
),
37+
],
1738
stmts: [
1839
RawStmt {
1940
stmt: SelectStmt(
@@ -30,17 +51,18 @@ Parse {
3051
val: Some(
3152
Node {
3253
node: Some(
33-
AConst(
34-
AConst {
35-
isnull: false,
54+
ColumnRef(
55+
ColumnRef {
56+
fields: [
57+
Node {
58+
node: Some(
59+
AStar(
60+
AStar,
61+
),
62+
),
63+
},
64+
],
3665
location: 7,
37-
val: Some(
38-
Ival(
39-
Integer {
40-
ival: 1,
41-
},
42-
),
43-
),
4466
},
4567
),
4668
),
@@ -52,7 +74,23 @@ Parse {
5274
),
5375
},
5476
],
55-
from_clause: [],
77+
from_clause: [
78+
Node {
79+
node: Some(
80+
RangeVar(
81+
RangeVar {
82+
catalogname: "",
83+
schemaname: "",
84+
relname: "films",
85+
inh: true,
86+
relpersistence: "p",
87+
alias: None,
88+
location: 14,
89+
},
90+
),
91+
),
92+
},
93+
],
5694
where_clause: None,
5795
group_clause: [],
5896
group_distinct: false,
@@ -71,7 +109,7 @@ Parse {
71109
rarg: None,
72110
},
73111
),
74-
range: 55..64,
112+
range: 22..42,
75113
},
76114
],
77115
}

0 commit comments

Comments
 (0)