MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

Syntax error in: date < date + interval #1096

Closed pavel-francirek closed 10 months ago

pavel-francirek commented 10 months ago

Strange error that looks like adding interval to date results in interval type (not date). Example traceback:

ProgrammingError: (sqlalchemy.dialects.postgresql.asyncpg.ProgrammingError) <class 'asyncpg.exceptions.UndefinedFunctionError'>: operator does not exist: date < interval
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
[SQL: 
        SELECT
            *
        FROM result
        WHERE date_create >= %s
            AND date_create < %s + INTERVAL '1 day'
         ORDER BY date_create]
[parameters: (datetime.date(2021, 1, 1), datetime.date(2021, 1, 31))]
(Background on this error at: https://sqlalche.me/e/14/f405) while handling path /api/v1/result/
Traceback of APIApp (most recent call last):

  UndefinedFunctionError: operator does not exist: date < interval
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
    File /usr/lib/python3/dist-packages/sqlalchemy/dialects/postgresql/asyncpg.py, line 399, in _prepare_and_execute
    prepared_stmt, attributes = await adapt_connection._prepare(

    File /usr/lib/python3/dist-packages/sqlalchemy/dialects/postgresql/asyncpg.py, line 641, in _prepare
    prepared_stmt = await self._connection.prepare(operation)

    File /usr/lib/python3/dist-packages/asyncpg/connection.py, line 566, in prepare
    return await self._prepare(

    File /usr/lib/python3/dist-packages/asyncpg/connection.py, line 584, in _prepare
    stmt = await self._get_statement(

    File /usr/lib/python3/dist-packages/asyncpg/connection.py, line 398, in _get_statement
    statement = await self._protocol.prepare(

    File asyncpg/protocol/protocol.pyx, line 168, in prepare
pavel-francirek commented 10 months ago

sorry, my fault