Summary
validate_with_schema() does not expose VALUES columns to the enclosing query. It rejects both the default column1 names and explicit column aliases.
Reproduction
pip install polyglot-sql==0.12.1
import polyglot_sql
schema = {"tables": [{"name": "orders", "columns": [{"name": "total", "type": "INT"}]}]}
for sql in (
"WITH inventory AS (SELECT column1 AS product_id FROM VALUES (1)) "
"SELECT product_id FROM inventory",
"SELECT inventory_rows.product_id FROM VALUES (1) AS inventory_rows(product_id)",
):
result = polyglot_sql.validate_with_schema(sql, schema, dialect="snowflake")
print(result.valid, [(error.code, error.message) for error in result.errors])
Actual
False [('E201', "Unknown column 'column1' (not found in any referenced table)")]
False [('E222', "Unknown table or alias 'inventory_rows' referenced by column 'product_id'")]
Expected
Both queries are valid. A VALUES source provides column1..columnN by default, or its declared column aliases, under its table alias.
Summary
validate_with_schema()does not exposeVALUEScolumns to the enclosing query. It rejects both the defaultcolumn1names and explicit column aliases.Reproduction
Actual
Expected
Both queries are valid. A
VALUESsource providescolumn1..columnNby default, or its declared column aliases, under its table alias.