You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've checked against the latest version of SQLGlot (23.12.2) and can confirm that what I'm trying to do still doesn't work.
I'm trying to create an update dynamically with a join and I'm starting to wonder if update is missing a join argument.
I've tried to construct the expression that I need directly but it's getting a bit complex.
It could be that I'm just missing some documentation on how to handle this.
My specific example is using the TSQL dialect, I do not know if the update syntax differs across SQL Engines, I've tried to keep the example as agnostic as possible.
It seems that SQLGlot is capable of understanding such queries e.g.
fromsqlglotimportparse_oneraw_sql="""UPDATE Table_ASET Table_A.col1 = Table_B.col1, Table_A.col2 = Table_B.col2FROM Some_Table AS Table_A INNER JOIN Other_Table AS Table_B ON Table_A.id = Table_B.idWHERE Table_A.col3 = 'cool'"""parsed_sql=parse_one(raw_sql)
But I'm not sure how to get the same output when building the same statement programatically.
This was my first attempt, expecting I might be able to put it in to the from_ argument.
fromsqlglot.expressionsimportupdateupdate_properties= {
"Table_A.col1": "Table_B.col1",
"Table_A.col2": "Table_B.col1",
}
update(
"Table_A",
update_properties,
"Table_A.col3 = 'cool'",
"Some_Table AS Table_A INNER JOIN Other_Table AS Table_B ON Table_A.id = Table_B.id"
)
this gives me a ParseError as I guess it can't handle the join.
I then tried to use parse_one with just the from and join parts to get the expression I needed but realised it comes out as a select statement and the AST for the Table expression is different.
The Table expression has joins when parsing the update statement in full but not when trying to parse_one.
I've checked against the latest version of SQLGlot (23.12.2) and can confirm that what I'm trying to do still doesn't work.
I'm trying to create an update dynamically with a join and I'm starting to wonder if update is missing a join argument.
I've tried to construct the expression that I need directly but it's getting a bit complex.
It could be that I'm just missing some documentation on how to handle this.
My specific example is using the TSQL dialect, I do not know if the update syntax differs across SQL Engines, I've tried to keep the example as agnostic as possible.
It seems that SQLGlot is capable of understanding such queries e.g.
But I'm not sure how to get the same output when building the same statement programatically.
This was my first attempt, expecting I might be able to put it in to the
from_
argument.this gives me a ParseError as I guess it can't handle the join.
I then tried to use parse_one with just the from and join parts to get the expression I needed but realised it comes out as a select statement and the AST for the Table expression is different.
The Table expression has joins when parsing the update statement in full but not when trying to parse_one.
parse_one for FROM and JOIN
from part of parse_one for full update statement
Many thanks for your help in advance!
The text was updated successfully, but these errors were encountered: