Re: Unpacking a Python list in a query. - Mailing list psycopg

From Israel Ben Guilherme Fonseca
Subject Re: Unpacking a Python list in a query.
Date
Msg-id BANLkTi=jbxsNanQOk_9+eL24zDm9yLRuRA@mail.gmail.com
Whole thread Raw
In response to Re: Unpacking a Python list in a query.  (Sukhbir Singh <singheinstein@gmail.com>)
List 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@gmail.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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/psycopg

psycopg by date:

Previous
From: David Niergarth
Date:
Subject: Re: Unpacking a Python list in a query.
Next
From: Federico Di Gregorio
Date:
Subject: Re: performance of copy_from() vs. raw COPY command