sqlglot
sqlglot copied to clipboard
`qualify` optimization rule does not expand `RETURNING *` for UPDATE, INSERT and DELETE queries
optimized = optimize(
parse_one("DELETE FROM authors RETURNING *", dialect=dialect),
schema=schema,
dialect=dialect,
sql=query.sql(dialect=dialect),
rules=(
qualify,
),
expand_alias_refs=False,
allow_partial_qualification=True,
validate_qualify_columns=False,
quote_identifiers=False,
identify=False
)
This produces DELETE FROM authors RETURNING *. Expected DELETE FROM authors RETURNING authors.id as id, authors.name as name, authors.rating as rating
This is expected - the optimizer only works on queries or query-based-DDLs (e.g., CTAS statements) today. There are no plans to expand its support to statements like the one you've shared here for the time being.