Skip to content

Commit 8a6eb32

Browse files
authored
Merge pull request #95 from cvng/create-table-tests
2 parents 67f1ab0 + fbaf2bf commit 8a6eb32

13 files changed

+1725
-0
lines changed

Diff for: crates/codegen/src/get_node_properties.rs

+27
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ fn custom_handlers(node: &Node) -> TokenStream {
376376
tokens.push(TokenProperty::from(Token::Key));
377377
},
378378
protobuf::ConstrType::ConstrForeign => tokens.push(TokenProperty::from(Token::References)),
379+
protobuf::ConstrType::ConstrUnique => tokens.push(TokenProperty::from(Token::Unique)),
379380
_ => panic!("Unknown Constraint {:#?}", n.contype()),
381+
};
382+
if n.options.len() > 0 {
383+
tokens.push(TokenProperty::from(Token::With));
380384
}
381385
},
382386
"PartitionSpec" => quote! {
@@ -456,6 +460,29 @@ fn custom_handlers(node: &Node) -> TokenStream {
456460
tokens.push(TokenProperty::from(Token::For));
457461
tokens.push(TokenProperty::from(Token::Values));
458462
}
463+
if let Some(n) = &n.relation {
464+
match n.relpersistence.as_str() {
465+
// Unlogged
466+
"u" => tokens.push(TokenProperty::from(Token::Unlogged)),
467+
// Temporary
468+
"t" => tokens.push(TokenProperty::from(Token::Temporary)),
469+
_ => {},
470+
}
471+
if n.inh {
472+
tokens.push(TokenProperty::from(Token::Inherits));
473+
}
474+
}
475+
},
476+
"TableLikeClause" => quote! {
477+
tokens.push(TokenProperty::from(Token::Like));
478+
// CREATE_TABLE_LIKE_ALL
479+
if n.options == 0x7FFFFFFF {
480+
tokens.push(TokenProperty::from(Token::Including));
481+
tokens.push(TokenProperty::from(Token::All));
482+
} else {
483+
tokens.push(TokenProperty::from(Token::Excluding));
484+
tokens.push(TokenProperty::from(Token::All));
485+
}
459486
},
460487
"PartitionBoundSpec" => quote! {
461488
tokens.push(TokenProperty::from(Token::From));

Diff for: crates/parser/tests/data/statements/valid/0043.sql

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE UNLOGGED TABLE cities (name text, population real, altitude double, identifier smallint, postal_code int, foreign_id bigint);
2+
/* TODO: CREATE TABLE IF NOT EXISTS distributors (name varchar(40) DEFAULT 'Luso Films', len interval hour to second(3), name varchar(40) DEFAULT 'Luso Films', did int DEFAULT nextval('distributors_serial'), stamp timestamp DEFAULT now() NOT NULL, stamptz timestamp with time zone, "time" time NOT NULL, timetz time with time zone, CONSTRAINT name_len PRIMARY KEY (name, len)); */ SELECT 1;
3+
/* TODO: CREATE TABLE types (a real, b double precision, c numeric(2, 3), d char(4), e char(5), f varchar(6), g varchar(7)); */ SELECT 1;
4+
/* TODO: CREATE TABLE types (a geometry(point) NOT NULL); */ SELECT 1;
5+
CREATE TABLE tablename (colname int NOT NULL DEFAULT nextval('tablename_colname_seq'));
6+
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;
9+
/* TODO: CREATE TEMPORARY TABLE films_recent ON COMMIT DROP AS SELECT * FROM films WHERE date_prod > $1; */ SELECT 1;
10+
CREATE TABLE like_constraint_rename_cache (LIKE constraint_rename_cache INCLUDING ALL);
11+
CREATE TABLE distributors (did int, name varchar(40), UNIQUE (name) WITH (fillfactor=70)) WITH (fillfactor=70);

Diff for: crates/parser/tests/snapshots/statements/valid/[email protected]

+412
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
source: crates/parser/tests/statement_parser_test.rs
3+
description: CREATE TABLE like_constraint_rename_cache (LIKE constraint_rename_cache INCLUDING ALL);
4+
---
5+
Parse {
6+
cst: SourceFile@0..87
7+
CreateStmt@0..87
8+
Create@0..6 "CREATE"
9+
Whitespace@6..7 " "
10+
Table@7..12 "TABLE"
11+
Whitespace@12..13 " "
12+
RangeVar@13..41
13+
Ident@13..41 "like_constraint_renam ..."
14+
Whitespace@41..42 " "
15+
Ascii40@42..43 "("
16+
TableLikeClause@43..85
17+
Like@43..47 "LIKE"
18+
Whitespace@47..48 " "
19+
RangeVar@48..71
20+
Ident@48..71 "constraint_rename_cache"
21+
Whitespace@71..72 " "
22+
Including@72..81 "INCLUDING"
23+
Whitespace@81..82 " "
24+
All@82..85 "ALL"
25+
Ascii41@85..86 ")"
26+
Ascii59@86..87 ";"
27+
,
28+
errors: [],
29+
stmts: [
30+
RawStmt {
31+
stmt: CreateStmt(
32+
CreateStmt {
33+
relation: Some(
34+
RangeVar {
35+
catalogname: "",
36+
schemaname: "",
37+
relname: "like_constraint_rename_cache",
38+
inh: true,
39+
relpersistence: "p",
40+
alias: None,
41+
location: 13,
42+
},
43+
),
44+
table_elts: [
45+
Node {
46+
node: Some(
47+
TableLikeClause(
48+
TableLikeClause {
49+
relation: Some(
50+
RangeVar {
51+
catalogname: "",
52+
schemaname: "",
53+
relname: "constraint_rename_cache",
54+
inh: true,
55+
relpersistence: "p",
56+
alias: None,
57+
location: 48,
58+
},
59+
),
60+
options: 2147483647,
61+
relation_oid: 0,
62+
},
63+
),
64+
),
65+
},
66+
],
67+
inh_relations: [],
68+
partbound: None,
69+
partspec: None,
70+
of_typename: None,
71+
constraints: [],
72+
options: [],
73+
oncommit: OncommitNoop,
74+
tablespacename: "",
75+
access_method: "",
76+
if_not_exists: false,
77+
},
78+
),
79+
range: 0..86,
80+
},
81+
],
82+
}

0 commit comments

Comments
 (0)