supabase-community / supabase-csharp

A C# Client library for Supabase
https://github.com/supabase-community/supabase-csharp/wiki
MIT License
499 stars 50 forks source link

Postgrest.Exceptions.PostgrestException: {"code":"42883","details":null,"hint":"No operator matches the given name and argument types. You might need to add explicit type casts.","message":"operator does not exist: text @> unknown"} Dotnet Supabase #140

Closed joseadrianoemmanuel1999 closed 9 months ago

joseadrianoemmanuel1999 commented 10 months ago

Bug report

"code":"42883"

Describe the bug

I am trying to use this command in my project :

await _SupabaseClient
                      .From<Products>()
                      .Select("id,name,price,desc,brand_id:Brands(id,name),subcategory_id:Subcategories(id,name,category_id:Categories(id,name,gender)),Imgs(image),shop_id:users(id,fullname)")
                      .Filter(x=>x.brand_id.name.ToString(),Operator.Contains,new List<Object> {"Nike","Puma"}).Get();

When i try use have this is error:

Postgrest.Exceptions.PostgrestException: {"code":"42883","details":null,"hint":"No operator matches the given name and argument types. You might need to add explicit type casts.","message":"operator does not exist: text @> unknown"}

System information

acupofjose commented 9 months ago

Hm. Seems like something is not being translated into the query correctly... it should be using the operators like specified here. (Notes for implementing a fix)

Off the top of my head, I wonder if ?tags=cs.{example, new} is being sent incorrectly as ?tags=cs.{"example", "new"}.

Could you try the In operator instead and see if that works?

joseadrianoemmanuel1999 commented 9 months ago

Thanks to respond me, Yes i try use operator In and nothing is working.

acupofjose commented 9 months ago

I'm able to duplicate, but I'm not sure what the issue is with the CONTAINS operator. The request is being formed according to their documentation. I'm going to open an issue on the postgrest repo and see if they have an issue.

It looks like the functionality you're looking for is available using the IN operator though.

The following test case works (relative to the PostgrestTests part of the repo) as expected:

[TestMethod("filters: cs (list)")]
public async Task TestContainsFilterList()
{
    var client = new Client(BaseUrl);

    var filteredResponse = await client.Table<User>()
        .Filter(x => x.Username!, Operator.In, new List<string> { "dragarcia", "acupofjose" })
        .Get();

    filteredResponse.Models.ForEach(x => Assert.IsTrue(x.Username is "dragarcia" or "acupofjose"));
}
acupofjose commented 9 months ago

@joseadrianoemmanuel1999 the answer given the issue:

The contains operator @> does not work for text types. It's used for arrays, json(b) and others. Are you trying to query all the users with username that belong to a list of candidates? If so you can use like(any).

So please use the IN or LIKE operator!

joseadrianoemmanuel1999 commented 9 months ago

It's worked but it's sad other command fails, But thanks for help