On 09/16/2010 04:28 PM, Pykler wrote:
> It seems it is not possible to do this with bindparams, my workaround
> was as follows
>
> On Sep 16, 2:01 pm, Pykler <[email protected]> wrote:
>
>> engine.execute(sql.expression.text('''
>> select * from users where id in %s
>> '''% SqlTuple([1,2,3,4]))
>>
> Where SqlTuple is a tuple with a custom repr method to print without
> the trailing ,
>
If you are using PostgreSQL with psycopg2, you can pass arrays as
bindparams in certain situations. Basically, if you can put an
"ARRAY[...]::some_type[]" literal in the SQL text, then you use a
bindparam there instead.
engine.execute(
text('''select * from users where id = ANY (:ids)'''),
ids=[1,2,3,4])
I would imagine that other databases that support arrays would work
similarly. There is also a ghetto way where you format ids as a
delimited string, e.g. ",1,2,3,4," and use "select * from users where
:ids LIKE '%,' || id || ',%'". But you are probably better off
formatting the SQL directly like your workaround.
-Conor
--
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.