On Feb 23, 2011, at 6:25 PM, Bill Curtis wrote:

> I've noticed that when I call .filter() on a query, the bind parameters in 
> query.statement are named :id_1, :id_2, etc.
> 
> When you call .get() on a query, the params are called :param_1, etc.  
> 
> Is there a way to control what placeholder tokens are used for the bind 
> params?

yeah use bindparam():

        query.filter(MyClass.table == bindparam('foobar')).params(foobar=5)

or

        query.filter(MyClass.table == bindparam('foobar', value=5))

> 
> The reason I ask is I have a scheme by which my entire query templates are 
> hashed and used as part of a memcache key.
> 
> I have data in the memcache that is being placed there via a .get() call. I'm 
> trying to reconstruct the cache key at a later point by reconstructing (but 
> not executing) the query.  My hashes are coming out differently b/c the text 
> of the query templates differs as described.

The names generated by SQLalchemy, i.e. :id_1, :id_2, etc. are deterministic - 
they will always be the same for the same query.     If OTOH you're trying to 
get the SQLA Query object to exactly match SQL that is generated from something 
else, that seems like a pretty rough way to travel.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to