I wish I could pass bound variables as a dictionary not a list

From: "W(dot) Matthew Wilson" <matt(at)tplus1(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: I wish I could pass bound variables as a dictionary not a list
Date: 2011-07-20 00:24:06
Message-ID: CAGHfCUDwLAZUnBRYD0WC4TXhuxw6r5Rx6xZcqhDp8U3zFU+mfQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Every once in a while, I have to write a big gnarly query like

cursor.execute("""
select *
from table1
where (%s) > 99
and ...
""",

[a, a, b, b, c, c, a, a, b])

The point being that I have to repeat lots of parameters because I use
them in several where-clauses.

It would make these queries vastly easier to read and debug if I could
pass in bound variables as a dictionary, rather than as a tuple.

Is this possible?

Matt

--
W. Matthew Wilson
matt(at)tplus1(dot)com
http://tplus1.com

Responses

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2011-07-20 00:33:48 Re: I wish I could pass bound variables as a dictionary not a list
Previous Message Federico Di Gregorio 2011-07-05 08:35:36 Re: Named Cursors WITH HOLD