On 11/10/2016 05:24 AM, T Johnson wrote:
When I print a select statement, my bindparams show as %s instead of as named 
params. What could be the cause of this?

myparam
BindParameter('myparamname', 'hello', type_=Unicode())

print(table.c.colname == myparam)
table.colname = :myparamname

print(select([table.c.colname]).where (table.c.colname == myparam))
SELECT table.colname
FROM table
WHERE table.colname = %s

I tried to construct a toy example and couldn't reproduce my issue. So if this 
doesn't prompt any ideas, I'll work to reduce my repeatable example to 
something minimal and postable.

The reason this is important to me is that the %s hid a mistake I made in 
assigning the same name to two bindparams that should have had different 
values. This caused the actual value that was used during execution to be 
selected arbitrarily and produce undesirable results. Note that if I compiled 
with literal binds and executed, then I always got both distinct values 
(probably due to it using positional args) and received desireable results.

SQLite, MySQL and others use "format" (e.g. %s) as a default paramstyle, so if your Table belongs to a MetaData that's bound to an engine of that variety, you get %s.

One of many, many reasons that for years I've tried to hide the documentation for "bound metadata" as much as possible, it's an almost useless feature. Yet it survives in a blog posts and tutorials everywhere.





--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to