Re: Unpacking a Python list in a query.

Поиск
Список
Период
Сортировка
От Israel Ben Guilherme Fonseca
Тема Re: Unpacking a Python list in a query.
Дата
Msg-id BANLkTi=jbxsNanQOk_9+eL24zDm9yLRuRA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Unpacking a Python list in a query.  (Sukhbir Singh <singheinstein@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: David Niergarth
Дата:
Сообщение: Re: Unpacking a Python list in a query.
Следующее
От: Federico Di Gregorio
Дата:
Сообщение: Re: performance of copy_from() vs. raw COPY command