Skip to content
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

Support UPDATE ... FROM ( subquery ) in some dialects #694

Merged
merged 4 commits into from Nov 11, 2022

Conversation

unvalley
Copy link
Contributor

@unvalley unvalley commented Oct 28, 2022

Closes #534

Apply UPDATE .. FROM (subquery) for

  • BigQuery
  • Redshift
  • Snowflake
  • SQL Server
  • GenericDialect

src/parser.rs Outdated
@@ -5075,7 +5075,9 @@ impl<'a> Parser<'a> {
let table = self.parse_table_and_joins()?;
self.expect_keyword(Keyword::SET)?;
let assignments = self.parse_comma_separated(Parser::parse_assignment)?;
let from = if self.parse_keyword(Keyword::FROM) && dialect_of!(self is PostgreSqlDialect) {
let from = if self.parse_keyword(Keyword::FROM)
&& dialect_of!(self is PostgreSqlDialect | BigQueryDialect | SnowflakeDialect | RedshiftSqlDialect | MsSqlDialect)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unvalley please add the GenericDialect as well

fn parse_update_set_from() {
let sql = "UPDATE t1 SET name = t2.name FROM (SELECT name, id FROM t1 GROUP BY id) AS t2 WHERE t1.id = t2.id";
let dialects = TestedDialects {
dialects: vec![
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And add the generic dialect on tests as well please

@unvalley
Copy link
Contributor Author

unvalley commented Oct 30, 2022

@AugustoFKL Thank you for reviewing. I added GenericDialect to parse and test target.

Box::new(PostgreSqlDialect {}),
Box::new(BigQueryDialect {}),
Box::new(RedshiftSqlDialect {}),
Box::new(MsSqlDialect {}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unvalley sorry I missed this, I think Snowflake is missing in tests, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my fault. Thank you for checking!
I added Snowflake in 413195b .

Copy link
Contributor

@AugustoFKL AugustoFKL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

Thanks for the quick response

@coveralls
Copy link

coveralls commented Nov 11, 2022

Pull Request Test Coverage Report for Build 3448066476

  • 60 of 60 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 86.277%

Totals Coverage Status
Change from base Build 3448022004: 0.002%
Covered Lines: 11807
Relevant Lines: 13685

💛 - Coveralls

@alamb
Copy link
Collaborator

alamb commented Nov 11, 2022

I took the liberty of merging this PR to the master branch and resolving the conflicts (from #666). Sadly it did not quite make the 0.27 release

@alamb alamb merged commit 4b1dc1a into sqlparser-rs:main Nov 11, 2022
@unvalley unvalley deleted the update-from-subquery-#534 branch November 12, 2022 00:49
ggaughan added a commit to ggaughan/sqlparser-rs that referenced this pull request Jan 29, 2024
"UPDATE-FROM is supported beginning in SQLite version 3.33.0
(2020-08-14)." from https://www.sqlite.org/lang_update.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UPDATE ... FROM ( subquery ) only supported in PostgreSQL
4 participants