I have a problem when I try to perform a multiple update of my table using psycopg2. When I run this query
query ='UPDATE table SET isValid = false where id = %s and customerid = %s and filed in %s'
data = (id,customerid, fieldlist)
cursor.execute(query, data)
where id and customer id are both guid and fieldlist is a list of string
I obtain this error syntax error at or near "ARRAY":
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
psycopg2.errors.SyntaxError: syntax error at or near "ARRAY"
LINE 1: ...alse where id = 2 and customerid = 1 and filed in ARRAY['22/11/20', '23...
^
I know that the problem is in my fieldlist
variable but I can’t find a clever way to solve my problem.
Thanks
2
Answers
Per
psycopg2
docs Type adaption:Lists adaption:
So:
... filed = ANY(%s) ...
Since your
fieldlist
variable is of type ARRAY but you are using it as a Tuple list. You’ll have to utilise thetuple(fieldlist)
.Like so:
Refer to documentation for more details