From: | Paolo De Stefani <paolo(at)paolodestefani(dot)it> |
---|---|
To: | Psycopg <psycopg(at)postgresql(dot)org> |
Subject: | Query with boolean parameter |
Date: | 2022-03-18 23:56:28 |
Message-ID: | 8df15d1263aaa1a9d36eacb0e5b9a28e@paolodestefani.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
Hi all
Regarding query and parameter binding in psycopg3:
cur.execute('SELECT * FROM system.app_user WHERE can_edit_views = %s',
(True,))
<psycopg.Cursor [TUPLES_OK] [INTRANS] (host=localhost port=5433
user=postgres database=test4) at 0x127b7f0>
cur.execute('SELECT * FROM system.app_user WHERE can_edit_views IS %s',
(True,))
Traceback (most recent call last):
Python Shell, prompt 10, line 1
# Used internally for debug sandbox under external interpreter
File "C:\Python310\Lib\site-packages\psycopg\cursor.py", line 555, in
execute
raise ex.with_traceback(None)
psycopg.errors.SyntaxError: syntax error at or near "$1"
LINE 1: SELECT * FROM system.app_user WHERE can_edit_views IS $1
^
Is there any reason why the second query results in a syntax error?
I can use the first form but usually to check a boolean or null value in
SQL the IS [true|false|null]/ IS NOT [true|false|null] operator is used.
--
Paolo De Stefani
From | Date | Subject | |
---|---|---|---|
Next Message | Christophe Pettus | 2022-03-19 00:00:20 | Re: Query with boolean parameter |
Previous Message | Karsten Hilbert | 2022-02-12 09:39:44 | Re: exception psycopg.Error from psycopg2 to psycopg 3 |