Query with boolean parameter

Поиск
Список
Период
Сортировка
От Paolo De Stefani
Тема Query with boolean parameter
Дата
Msg-id 8df15d1263aaa1a9d36eacb0e5b9a28e@paolodestefani.it
обсуждение исходный текст
Ответы Re: Query with boolean parameter  (Christophe Pettus <xof@thebuild.com>)
Список 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



В списке psycopg по дате отправления:

Предыдущее
От: Karsten Hilbert
Дата:
Сообщение: Re: exception psycopg.Error from psycopg2 to psycopg 3
Следующее
От: Christophe Pettus
Дата:
Сообщение: Re: Query with boolean parameter