`Array.any` bugged?
I receive Query string compile errors when I use Array.any for postgres (cockroach) manager
from piccolo.table import Table
from piccolo.columns import (
Array,
Text,
)
class Helloworld(Table):
test = Array(Text(), null=True, default=[])
Helloworld.objects().where(Helloworld.text.any("a hello world string")).run_sync()
result:
asyncpg.exceptions.IndeterminateDatatypeError: could not determine data type of placeholder $1
The work around is:
from piccolo.columns.combination import WhereRaw
Helloworld.objects().where(WhereRaw("some raw equivalent")).run_sync()
@Jacky56 Sorry but, I can't reproduce the error in Postgres. I noticed you have a typo in your where query (the column name is wrong, it should be Helloworld.test.any not Helloworld.text.any) but that raise AttributeError: object of type 'Helloworld' has no attribute 'text', but other than that everything works in my case.
EDIT:
You are right for CockroachDB. I can reproduce that error which advises adding explicit type conversions to placeholder arguments.
Yeah, it's weird that CockroachDB requires the explicit type casting.
You can add an explicit type cast using one of these:
from piccolo.query.functions import Cast
from piccolo.querystring import QueryString
# This
await MyTable.select().where(MyTable.my_array_column.any(Cast(QueryString('{}', 'some_value'), Varchar())))
# Or just this:
await MyTable.select().where(MyTable.my_array_column.any(QueryString('{}'::varchar, 'some_value'))