sqlalchemy-views icon indicating copy to clipboard operation
sqlalchemy-views copied to clipboard

CreateView ignores bindparam

Open rectalogic opened this issue 4 years ago • 0 comments

If I use a bindparam in my view definition, it does not appear to be bound when creating the view. Is there a way to pass through bindparams?

>>> import sqlalchemy as sa
>>> from sqlalchemy_views import CreateView
>>> engine = sa.create_engine("postgresql:///?service=devrds")
>>> table = sa.Table("my_table", sa.MetaData(), sa.Column("col", sa.String(100), nullable=True))
>>> view = sa.table("my_view")
>>> definition = table.select().where(table.c.col == sa.bindparam("colval"))
>>> create_view = CreateView(view, definition)
>>> table.create(engine)
>>> engine.execute(create_view, colval="test")
/site/venv/lib/python3.8/site-packages/sqlalchemy_views/views.py:72: SAWarning: Bound parameter 'colval' rendering literal NULL in a SQL expression; comparisons to NULL should not use operators outside of 'is' or 'is not' (this warning may be suppressed after 10 occurrences)
  text += "AS %s\n\n" % compiler.sql_compiler.process(create.selectable,
<sqlalchemy.engine.cursor.LegacyCursorResult object at 0x7fdfcd4545b0>

rectalogic avatar Sep 22 '21 18:09 rectalogic