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

Range operators cannot be used inside or without quoting #3368

Closed
steve-chavez opened this issue Apr 2, 2024 · 6 comments · Fixed by #3574
Closed

Range operators cannot be used inside or without quoting #3368

steve-chavez opened this issue Apr 2, 2024 · 6 comments · Fixed by #3574
Labels
docs Only related to documentation

Comments

@steve-chavez
Copy link
Member

steve-chavez commented Apr 2, 2024

Problem

This works:

curl -g 'localhost:3000/ranges?range=adj.(3,10]&select=id'
[{"id":1}]

This doesn't:

curl -g 'localhost:3000/ranges?or=(range.adj.[3,10))&select=id'

{"code":"PGRST100","details":"unexpected \")\" expecting letter, digit, \"-\", \"->>\", \"->\" or delimiter(.)","hint":null,"message":"\"failed to parse logic tree ((range.adj.[3,10)))\" (line 1, column 19)"}

curl -g 'localhost:3000/ranges?or=(range.adj.(3,10])&select=id'

{"code":"PGRST100","details":"unexpected \"]\" expecting letter, digit, \"-\", \"->>\", \"->\" or delimiter (.)","hint":null,"message":"\"failed to parse logic tree ((range.adj.(3,10]))\" (line 1, column 19)"}

Possible Solutions

@wolfgangwalther
Copy link
Member

Did you try to quote the value instead?

curl -g 'localhost:3000/ranges?or=(range.adj."[3,10)")&select=id'

@steve-chavez
Copy link
Member Author

Works!

curl -g 'localhost:3000/ranges?or=(range.adj."(3,10]")&select=id'

[{"id":1}]

I guess still a bug though.

@wolfgangwalther
Copy link
Member

I guess still a bug though.

Huh? It works as designed. I really don't see the bug.

@steve-chavez
Copy link
Member Author

Right, maybe this is just a matter of docs then. It would be nice to have a mention about this gotcha on https://postgrest.org/en/v12/references/api/tables_views.html#operators

@steve-chavez steve-chavez added the docs Only related to documentation label Apr 10, 2024
@steve-chavez steve-chavez changed the title Ranges cannot be used inside or Range operators cannot be used inside or Apr 10, 2024
@steve-chavez steve-chavez changed the title Range operators cannot be used inside or Range operators cannot be used inside or without quoting Apr 10, 2024
@steve-chavez steve-chavez removed the bug label Apr 10, 2024
@wolfgangwalther
Copy link
Member

I think it should be in the next section, so not operators, but logical operators: https://postgrest.org/en/v12/references/api/tables_views.html#logical-operators

@laurenceisla
Copy link
Member

Maybe this is related and should be added to the docs too. From this discussion #3466 (comment):

curl --globoff 'http://example.com/table?select=*&and=(column->jsonlist.cs.["foo=()"]'

results in

{"code":"22P02","details":"Token \"\"foo=(\" is invalid.","hint":null,"message":"invalid input syntax for type json"}

The solution is to wrap the whole JSON array value inside quotations, (not just the items). That is:

curl --globoff 'http://example.com/table?select=*&and=(column->jsonlist.cs."[\"foo=()\"]"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Only related to documentation
3 participants