Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.any bugged? #1126

Open
Jacky56 opened this issue Nov 12, 2024 · 2 comments
Open

Array.any bugged? #1126

Jacky56 opened this issue Nov 12, 2024 · 2 comments

Comments

@Jacky56
Copy link

Jacky56 commented Nov 12, 2024

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()
@sinisaos
Copy link
Member

sinisaos commented Nov 12, 2024

@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.

@dantownsend
Copy link
Member

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'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants