tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.39k stars 359 forks source link

'__startswith’ modifier didn’t work fine on Oracle DB. #1470

Open wxmaseve opened 10 months ago

wxmaseve commented 10 months ago

When using the '__startswith' modifier on Oracle DB, the data type of the automatically generated CAST function is only converted to 'VARCHAR' with no length, resulting in the following error.

ORA-00906: Left parenthesis missing

ex.)

async def get_counter(self, current_date):
        result = await (
            MY_TABLE
            .filter(create_dtm__startswith=current_date)
            .annotate(count=Count("*"))
            .group_by("status")
            .values("status", "count")
        )

        return result

actual query like that.

SELECT "RESULT" "status",COUNT(*) "count" FROM "MY_TABLE" WHERE CAST("DATETIME" AS VARCHAR) LIKE '20230829%' ESCAPE '\' GROUP BY "RESULT"