| From: | Israel Ben Guilherme Fonseca <israel(dot)bgf(at)gmail(dot)com> |
|---|---|
| To: | Sukhbir Singh <singheinstein(at)gmail(dot)com> |
| Cc: | David Niergarth <dn(at)hddesign(dot)com>, psycopg(at)postgresql(dot)org |
| Subject: | Re: Unpacking a Python list in a query. |
| Date: | 2011-06-24 19:54:25 |
| Message-ID: | BANLkTi=jbxsNanQOk_9+eL24zDm9yLRuRA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | psycopg |
Hmm, I was trying to remember why lists and tuples were different and found
this in the docs:
Python lists are converted into PostgreSQL ARRAYs:
-
>>> cur.mogrify("SELECT %s;", ([10, 20, 30], ))
'SELECT ARRAY[10, 20, 30];'
Python tuples are converted in a syntax suitable for the SQL IN operator and
to represent a composite type:
>>> cur.mogrify("SELECT %s IN %s;", (10, (10, 20, 30)))
'SELECT 10 IN (10, 20, 30);'
Just remember that. :)
2011/6/24 Sukhbir Singh <singheinstein(at)gmail(dot)com>
> Hi,
>
> > Actually, a list or a tuple will work just fine.
>
> Indeed, it does work. I somehow didn't try the most obvious solution
> to this, focusing on unpacking all the time :-)
>
> Thank you.
>
> --
> Sent via psycopg mailing list (psycopg(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/psycopg
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Federico Di Gregorio | 2011-06-25 16:45:16 | Re: performance of copy_from() vs. raw COPY command |
| Previous Message | Sukhbir Singh | 2011-06-24 19:40:23 | Re: Unpacking a Python list in a query. |