-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
When embedding with top-level filtering (inner join), empty parentheses should be allowed #2340
Comments
I see your point. We were planning to change the GET /film?exists=film_category |
I also need to do things like that:
(Actually, that's the vast majority of my use cases. The former one, without any additional filter criteria, is rarer, and was cited here for simplification purposes) As far as I understand how PostgREST works, currently I need to include How would you do that with your proposed syntax ? (It would be great if PostgREST could automatically infer the necessity to perform an |
To give some figures, in my production database, the equivalent of the Therefore, when using this work-around:
I get a 12 MB JSON response, containing thousands of useless lines... Whereas with a theoretical:
The JSON response would be only 80 KB... So, that makes a great difference! |
Thinking about it once again: if you try to make an analogy with the SQL syntax, then I understand that the Maybe it is not for nothing that there is also a |
Yes, that would also be possible with GET /film?exists=film_category&film_category.category_id=not.eq.1
That one was fixed in #2133, v10 will include it.
Check the samples of the generated queries in #1978 (comment), it's actually a LATERAL JOIN plus One other thing we could try to support with exists is doing OR across different tables: #2014 (comment) |
exists
filter)
exists
filter)exists
filter - When embedding with top-level filtering (inner join), empty parentheses should be allowed
Just noted that the anti-join mentioned on #1949 (comment) could be supported with a We could also add an |
Also considering #1949 (comment), that also suggests to just go with the non-breaking changes for now - and then open another issue where we can discuss a "new query syntax" that could get a few things straight:
Since both things are independent of each other, would you please consider allowing empty parenthesis in the actual query syntax? (is it difficult to implement? Does it breaks anything?) Or do you expect the breaking new query syntax to be shipped in production so quickly that it is not worth correcting the current syntax? Thank you for considering this possibility. |
Yes, using the ideas on #1414 (comment) now I think an empty parenthesis grants us a simpler/better syntax than GET /projects?select=*,clients()&clients=not.is.null
This would not be a breaking change since empty parenthesis right now gives a syntax error curl 'localhost:3000/projects?select=*,clients()'
{"code":"42703","details":null,"hint":"Perhaps you meant to reference the column \"projects.client_id\".","message":"column projects.clients does not exist"} |
Great. Then we can go on this. |
exists
filter - When embedding with top-level filtering (inner join), empty parentheses should be allowed
Environment
Description of issue
Trying to do :
I get an error message
column film.film_category does not exist
.Firstly, the error message is out of touch, since we are performing an
INNER JOIN
and the columns / relation does exist.Secondly, it should not trigger an error: this query is perfectly legitimate and feasible ("I want all the films that do have a category, but I'm not interested in knowing what are their precise categories, therefore I would like to have a reduced JSON, not containing the film_category data, i.e. just filtering the top-level on "has a film_category", but not embedding the data)
What I have to do as a work-around: put any dummy column inside the parentheses, so that I don't get an error message anymore:
And then I get a fat JSON body response, where I'm trashing all this embedded data... (waste of bandwidth + slow web app because of that)
Steps to reproduce
Let's take a sample database from https://www.postgresqltutorial.com/postgresql-sample-database/.
The relevant schema is as follows:
Populate those 3 tables as provided on this page, but then remove the category of some films, for example with:
DELETE FROM film_category WHERE category_id > 1; -- only 64 films will keep their category
Now suppose you're interested to know what are those 64 films which still has a category, but you don't want to embed their categories.
Suggestions / Discussion
If ever it's only a problem of syntax / parsing of the query string, not allowing any empty parentheses, then may I suggest to use a special keyword that would mean "no columns at all". It could be some reserved keyword from the SQL syntax, such as "NULL", so that we're pretty sure nobody would ever have a column with such a name in his/her database:
(Currently says "column film_category.NULL does not exist", which is true)
The text was updated successfully, but these errors were encountered: