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

Querying JSON columns with the special symbols #505

Open
2 tasks done
noskovvkirill opened this issue Nov 16, 2023 · 3 comments
Open
2 tasks done

Querying JSON columns with the special symbols #505

noskovvkirill opened this issue Nov 16, 2023 · 3 comments
Labels
bug Something isn't working postgrest-patch-needed Requires a change on PostgREST

Comments

@noskovvkirill
Copy link

noskovvkirill commented Nov 16, 2023

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Hi! We are trying to query the data from our jsonb column that has a special symbol @.
We are following the recommended spec by schema-dts

This is an example of code snippet we run:

   const { data, error } = await supabase
          .from('item')
          .select(
            `*, userId, media3Id(*), blockId!inner(*, media3Id!inner(*), consumptionId), newId, customData`,
          )
          .eq('media3Id->data->>schemaOrg2->>@type', schemaPrefix)
          .eq('userId', input.userId)
          .order('createdAt', { ascending: false });
        if (error) {

This is the result that we see

unexpected "@" expecting "-", digit or field name (* or [a..z0..9_$])

Is there anything that we are missing?

Screenshot 2023-11-16 at 12 03 42

To Reproduce

  1. Insert data into the jsonb column formatted as schema-dts with @type field
  2. Query the data by @type using supabase-js client
@noskovvkirill noskovvkirill added the bug Something isn't working label Nov 16, 2023
@steve-chavez steve-chavez transferred this issue from supabase/supabase-js Nov 16, 2023
@steve-chavez steve-chavez added the postgrest-patch-needed Requires a change on PostgREST label Nov 16, 2023
@steve-chavez
Copy link
Member

Thanks for the report. I can reproduce:

curl 'localhost:3000/bets?data_json->@type=eq.4'

{"code":"PGRST100","details":"unexpected \"@\" expecting \"-\", digit or field name (* or [a..z0..9_$])","hint":null,"message":"\"failed to parse tree path (data_json->@type)\" (line 1, column 12)"}

@steve-chavez
Copy link
Member

steve-chavez commented Nov 17, 2023

As a workaround, you could do:

.eq('media3Id->data->>schemaOrg2', {"@type": 1})

I've confirmed this works:

curl 'localhost:3000/jsontest?json->a->b=eq.\{"@type":1\}'

[{"json":{"a": {"b": {"@type": 1}}},"integer":1}]

@laurenceisla
Copy link
Contributor

laurenceisla commented Dec 2, 2023

Wrapping the key in quotations seems to work:

curl "http://localhost:3000/jsonvals?a->>\"@key\"=eq.1"
[{"@key":"1"}]

Doing this should work as another workaround:

.eq('media3Id->data->>schemaOrg2->>"@type"', schemaPrefix)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working postgrest-patch-needed Requires a change on PostgREST
Projects
None yet
Development

No branches or pull requests

3 participants