-
Notifications
You must be signed in to change notification settings - Fork 606
Add support for generated virtual columns with expression #1051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9618cda
05ac5bc
ec986b0
f0d0f5b
6d69a43
2887501
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -507,6 +507,18 @@ fn parse_create_table_comment_character_set() { | |
} | ||
} | ||
|
||
#[test] | ||
fn parse_create_table_gencol() { | ||
let sql_default = "CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a * 2))"; | ||
mysql_and_generic().verified_stmt(sql_default); | ||
|
||
let sql_virt = "CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a * 2) VIRTUAL)"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about adding additional support to the AST so you can recover the original SQL --- as implemented now this change will not permit people to know when the original query had There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Virtual is the default, so adding the marker doesn't make a logical difference (at least in the databases I found that support this). Elsewhere in the tests, it looks like you don't preserve differences like this - e.g. If so, I would probably introduce an enum called something like (For my next PR, I'm planning to make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it is true that this crate is not always consistent. However, for newly added code let's try and preserve the ability to round trip the AST (though I see there is no note describing that detail on https://github.com/sqlparser-rs/sqlparser-rs -- I will try and add a note when I have time)
yes, please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, the latest commit (6d69a43) preserves the distinction between I've called the new field & enum There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filed #1052 to document this property |
||
mysql_and_generic().verified_stmt(sql_virt); | ||
|
||
let sql_stored = "CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a * 2) STORED)"; | ||
mysql_and_generic().verified_stmt(sql_stored); | ||
} | ||
|
||
#[test] | ||
fn parse_quote_identifiers() { | ||
let sql = "CREATE TABLE `PRIMARY` (`BEGIN` INT PRIMARY KEY)"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,18 @@ fn parse_create_sqlite_quote() { | |
} | ||
} | ||
|
||
#[test] | ||
fn parse_create_table_gencol() { | ||
let sql_default = "CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a * 2))"; | ||
sqlite_and_generic().verified_stmt(sql_default); | ||
|
||
let sql_virt = "CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a * 2) VIRTUAL)"; | ||
sqlite_and_generic().verified_stmt(sql_virt); | ||
alamb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let sql_stored = "CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a * 2) STORED)"; | ||
sqlite_and_generic().verified_stmt(sql_stored); | ||
} | ||
|
||
#[test] | ||
fn test_placeholder() { | ||
// In postgres, this would be the absolute value operator '@' applied to the column 'xxx' | ||
|
@@ -435,7 +447,6 @@ fn sqlite_with_options(options: ParserOptions) -> TestedDialects { | |
|
||
fn sqlite_and_generic() -> TestedDialects { | ||
TestedDialects { | ||
// we don't have a separate SQLite dialect, so test only the generic dialect for now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 nice drive by cleanup |
||
dialects: vec![Box::new(SQLiteDialect {}), Box::new(GenericDialect {})], | ||
options: None, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 looks good to me -- I don't have a better name for this