Skip to content

validate_with_schema skips the query inside INSERT ... SELECT #474

Description

@kvlonge

Summary

validate_with_schema() does not validate the query inside INSERT ... SELECT. An unknown column is reported in a plain SELECT but not when the same SELECT feeds an INSERT.

Reproduction

pip install polyglot-sql==0.12.1
import polyglot_sql

schema = {"tables": [
    {"name": "orders", "columns": [{"name": "order_id", "type": "INT"}]},
    {"name": "order_archive", "columns": [{"name": "order_id", "type": "INT"}]},
]}
for sql in (
    "SELECT missing FROM orders",
    "INSERT INTO order_archive (order_id) SELECT missing FROM orders",
):
    result = polyglot_sql.validate_with_schema(sql, schema, dialect="postgres")
    print(result.valid, [(error.code, error.message) for error in result.errors])

Actual

False [('E201', "Unknown column 'missing' in table 'orders'")]
True []

Expected

Both statements are invalid with the same E201 error. The source query of INSERT ... SELECT should be validated like a standalone SELECT.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions