#34434: psycopg 3 cursor.execute no longer accepts Python tuple binding
-------------------------------------+-------------------------------------
               Reporter:  David      |          Owner:  nobody
  Burke                              |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  4.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 This may be a bug or a missing feature of psycopg 3. If expected, it may
 be worth mentioning as a breaking change when using psycopg3.

 The following Django code works with psycopg2. Notice the usage of a tuple
 with the "in" statement.

 cursor.execute("select 1 where 1 in %s", ((1,),)

 But in psycopg 3 it gives an error

 django.db.utils.ProgrammingError: syntax error at or near "'{1}'"
 LINE 1: select 1 where 1 in '{1}'::int2[]

 A fix is to use ANY with a list. It must specifically be a list and not a
 tuple.

 cursor.execute("select 1 where 1 = ANY(%s)", ([1],))

 With a tuple, we get the error

 django.db.utils.ProgrammingError: syntax error at or near "'(1)'"
 LINE 1: select 1 where 1 in '(1)'

 I would expect execute to treat a Python list and tuple the same when
 binding to a postgresql parameter. But this is not so.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34434>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701870fee944c-1961dbd3-fa00-43e7-906f-43a0345cb450-000000%40eu-central-1.amazonses.com.

Reply via email to