sqlglot icon indicating copy to clipboard operation
sqlglot copied to clipboard

`qualify` optimization rule does not expand `RETURNING *` for UPDATE, INSERT and DELETE queries

Open devfros opened this issue 6 months ago • 1 comments

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

devfros avatar May 11 '26 15:05 devfros

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.

georgesittas avatar May 11 '26 15:05 georgesittas