Re: Adaptation in psycopg3
От | Daniele Varrazzo |
---|---|
Тема | Re: Adaptation in psycopg3 |
Дата | |
Msg-id | CA+mi_8Z=nPj4ZiS7Z8CyPtOgAosMdUd_wh6o0ZeRs2rsgNBMBg@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Adaptation in psycopg3 (listas <listas@soft-com.es>) |
Ответы |
Re: Adaptation in psycopg3
|
Список | psycopg |
On Wed, 25 Nov 2020 at 18:00, listas <listas@soft-com.es> wrote: > Thank for your replies, I will use "=any(params list)" in psycopg3 No problem. But if it was not clear, this is something that works already in psycopg2 too: it could be useful if you want to port code later. > The second question is: if psycopg3 is going to do the automatic cast of > the types, will it be able to distinguish between a json and a list of > values?. > Example: > > data = ["a", "b", "c"] > idList = [4,7,2] > > cursor.execute("update mytable set jsfield=%s where id = any(%s)", > (data, idList)) > > What will be the correct syntax in this case? You would do like in psycopg2. There isn't a single json type in python (it could be a list, dict, number, None...) so there is a "Json" wrapper to tell psycopg to pass e.g. a json number rather than a number-number: https://www.psycopg.org/docs/extras.html?highlight=json#json-adaptation What you would do, both in psycopg2 and 3, would be something like: cursor.execute("update mytable set jsfield=%s where id = any(%s)", (Json(data), idList)) Code like this should work in both versions. Cheers -- Daniele
В списке psycopg по дате отправления: