Repository navigation
Conversation
sqlglot parses juxtaposition (`price quantity`) and a trailing AS as an Alias. The wrap and first-token-quoted fallbacks already refuse that shape, but a successful bare parse still returned the tree, so an ANSI_SQL or vendor dialect entry printed Validation PASSED and parse_tree handed name checks a tree whose alias identifier was never a column. Reject an Alias root on that success path, in every dialect. CAST(x AS t) is Cast and stays valid. parse_tree is then None, so scope leaves the error to the SQL check. Signed-off-by: Prithvi S <prithvisivasankar@gmail.com>
vigneshio
left a comment
There was a problem hiding this comment.
This PR covers what #777 left open: the Alias-root check on the bare parse success path. Wrap and quote-retry already reject that shape in every dialect, parse_tree going None keeps no_such_field out of scope, and CAST(x AS t) still parses as a Cast. INTERVAL stays a vendor form.
I added one related case to the new parametrize list, a IS, and kept a IS NULL as valid next to CAST.
#779 still composes with this, so I don't think this PR needs to wait on it.
CC: @jbonofre
| "SUM(price) no_such_field", | ||
| "SUM(orders.price) AS total", | ||
| "a b", | ||
| "a AS b", |
There was a problem hiding this comment.
a IS is the same Alias root (a AS IS) as a b, and #777 already pins it for OSSIE_SQL_2026. Adding it to this list, and a IS NULL next to the CAST case so that cousin stays accepted in ANSI_SQL, would cover the IS pair the way juxtaposition is covered here.
jbonofre
left a comment
There was a problem hiding this comment.
LGTM! Rejecting an exp.Alias root on the bare parse_one success path in _parse_sql_expression aligns all dialects with the wrap/quote fallbacks and ensures parse_tree returns None so downstream checks don't inspect an alias tree.
|
I opened #782 to fix the CI. |
sqlglot parses a missing operator (
price quantity) and a trailingASas an Alias._parse_sql_expressionreturned that tree as success, so the wrap/quote fallbacks that already refuse an Alias never ran.no_such_fieldinSUM(price) no_such_fieldsat in the alias slot, so name checks never saw it.#777 already fails those shapes for portable
sql:. An ANSI_SQL or vendor dialect entry with the same text still printed Validation PASSED. This rejects an Alias root on the parse success path in every dialect, matching the fallbacks.CAST(x AS t)is Cast and stays valid.parse_treeis then None, so scope leaves the error to the SQL check.Follow-up leftover after #777. #779 moves the portable construct walk into parse; it still leaves vendor dialects alone.
Reject an Alias root from
_parse_sql_expressionin every dialect, so juxtaposition and a trailingASfail SQL validation (andparse_treeis None) instead of passing as a named expression.Related
Leftover from #777. No open issue.