Describe the bug
Check constraint reflection strips brackets from some expressions such that they are syntactically invalid
Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected
No response
SQLAlchemy Version in Use
2.0.48
DBAPI (i.e. the database driver)
psycopg2
Database Vendor and Major Version
PostgreSQL 17
Python Version
3.14
Operating system
macOS
To Reproduce
from sqlalchemy import (
CheckConstraint,
Column,
Integer,
MetaData,
Table,
create_engine,
inspect,
)
from sqlalchemy.schema import CreateTable
def main() -> None:
engine = create_engine("postgresql:///issue13157")
foo = Table(
"foo",
MetaData(),
Column("id", Integer),
Column("x", Integer),
Column("y", Integer),
CheckConstraint(
"(x IS NULL OR y IS NULL) AND (x IS NULL OR y IS NULL)",
name="broken",
),
)
with engine.connect() as conn:
conn.execute(CreateTable(foo))
inspector = inspect(conn)
(broken,) = inspector.get_check_constraints(foo.name)
print(broken["sqltext"])
if __name__ == "__main__":
main()
Error
output:
x IS NULL OR y IS NULL) AND (x IS NULL OR y IS NULL
Additional context
No response
Describe the bug
Check constraint reflection strips brackets from some expressions such that they are syntactically invalid
Optional link from https://docs.sqlalchemy.org which documents the behavior that is expected
No response
SQLAlchemy Version in Use
2.0.48
DBAPI (i.e. the database driver)
psycopg2
Database Vendor and Major Version
PostgreSQL 17
Python Version
3.14
Operating system
macOS
To Reproduce
Error
output:
Additional context
No response