Replies: 3 comments 9 replies
-
We will not parse the SQL statement in order to figure out if a You can use |
Beta Was this translation helpful? Give feedback.
-
Ok. I didn't know if you were parsing them or not. It was just an observation.
All of these options require editing the query. I'm running user-defined SQL so that's not an option. I worked around by not using parameters at all. I'll note that although I much, much prefer psycopg's named parameter support this is not an issue with asyncpg's plain postgres parameter syntax: import asyncio
import datetime
import asyncpg
async def main() -> None:
conn = await asyncpg.connect('postgres://postgres:postgres@localhost:54320/postgres')
await conn.execute('DROP TABLE IF EXISTS test')
await conn.execute('CREATE TABLE test (ts TIMESTAMPTZ NOT NULL, msg TEXT NOT NULL)')
print(
await conn.fetch(
"""
SELECT *
FROM test
WHERE ts > $1 AND msg LIKE '%bar%'
""",
datetime.datetime(2015, 10, 21, 14, 28, 0),
)
)
asyncio.run(main()) Is there a world where psycopg supports the |
Beta Was this translation helpful? Give feedback.
-
@adriangb have you tried using a Raw Cursor: https://www.psycopg.org/psycopg3/docs/advanced/cursors.html#raw-query-cursors which uses libpq/asyncpg "$1" notation? |
Beta Was this translation helpful? Give feedback.
-
I generally understand why this example doesn't work with
psycopg
:And if you use positional parameters you get:
Could something be done to make it work?
Two things I can see:
%
inside of a literal should always be ignoredSELECT 'A' % 'a'
forpgtrgm
)Beta Was this translation helpful? Give feedback.
All reactions