> -----Original Message-----
> From: sqlalchemy@googlegroups.com 
> [mailto:sqlalch...@googlegroups.com] On Behalf Of Faheem Mitha
> Sent: 20 January 2009 22:05
> To: sqlalchemy@googlegroups.com
> Subject: [sqlalchemy] passing tuple argument into 
> sqlalchemy.sql.text string
> 
> 
> 
> Hi,
> 
> I've got a query as follows:
> 
> from sqlalchemy.sql import text
> 
> gq = text("""
> SELECT decode_genotype(cell.snpval_id, snp.allelea_id, 
> snp.alleleb_id) FROM cell JOIN snp ON snp.fid = 
> cell.snp_id WHERE cell.patient_chipid IN ('DUKE00001_plateA_A10.CEL', 
> 'DUKE00001_plateA_A11.CEL')
>     """)
> I want to pass in the tuple as an argument, and was wondering 
> how to do 
> it.
> 
> So, I'm looking for something conceptually like
> 
> gq = text("""
> SELECT decode_genotype(cell.snpval_id, snp.allelea_id, 
> snp.alleleb_id) FROM cell JOIN snp ON snp.fid = 
> cell.snp_id WHERE cell.patient_chipid IN :plist
>     """)
> 
> gq = conn.execute(gq, plist="('DUKE00001_plateA_A10.CEL', 
> 'DUKE00001_plateA_A11.CEL')")
> 
> Note, I want to pass in a tuple of arbitary length, so 
> changing this to 
> pass two string arguments would not do. Perhaps I'm supposed 
> to pass in 
> some bindparams too, but I don't know what type I should be using.
> 
>                                                            
> Regards, Faheem.
> 

I'm not sure you can do that in the general case. I think bind
parameters (in the DBAPI sense) are only really intended for
substituting individual query parameters, not lists.

If you are happy to regenerate your query each time you want to execute
it, you could create a function which generates a string of the form
"(:p0, :p1, :p2, :p3)" for the given tuple length, and appends that to
the query.

If you use the SQLAlchemy expression language to build that query, it'll
do that for you automatically.

Hope that helps,

Simon

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

Reply via email to