Summary
validate_with_schema() does not let a LATERAL subquery reference a source that appears earlier in the same FROM clause.
Reproduction
pip install polyglot-sql==0.12.1
import polyglot_sql
schema = {"tables": [{"name": "orders", "columns": [{"name": "total", "type": "INT"}]}]}
sql = """
SELECT nested.value
FROM orders AS orders_source,
LATERAL (SELECT orders_source.total AS value) AS nested
"""
result = polyglot_sql.validate_with_schema(sql, schema, dialect="snowflake")
print(result.valid, [(error.code, error.message) for error in result.errors])
Actual
False [('E222', "Unknown table or alias 'orders_source' referenced by column 'total'")]
Expected
The query is valid. A LATERAL derived table is correlated, so orders_source is in scope inside it.
Summary
validate_with_schema()does not let aLATERALsubquery reference a source that appears earlier in the sameFROMclause.Reproduction
Actual
Expected
The query is valid. A
LATERALderived table is correlated, soorders_sourceis in scope inside it.