-
-
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
Unexpected behavior for computed relationships using scalar functions (`returns <tablename>) #2481
Comments
There are two options we could go for:
The issue may be in this line: postgrest/src/PostgREST/DbStructure.hs Line 719 in 38ecaa4
And adapting the query that calls the RPC. |
I think we should disallow and document it. The problem with not including a I believe we should enforce this where we can otherwise it can lead to performance problems down the line. |
Please don't. The function is not inlineable, because we currently have it in the In this case it would be inlineable. This might also be a much better approach to the whole Plus, the new computed relationship feature is not only about relationships, but it is also a "computed columns on steroids" feature. A bit more general. Something that we couldn't do with regular computed columns before: Select only some of the fields from a computed column that returns a composite type: CREATE TABLE x (
y INT
);
CREATE FUNCTION abc(x, OUT a INT, OUT b INT, OUT c INT)
-- ... With regular computed column syntax I would always get something like this: {
"y": 1,
"abc": {
"a": 2,
"b": 3,
"c": 4
}
} But with the new syntax, I could do something like {
"y": 1,
"abc": {
"a": 2
}
} |
For a scalar function, the wiki states it must meet the following conditions to be inlineable:
So I think inlining a scalar function is not particularly attractive.
Not exactly the same, but it can be worked around as {
"y": 1,
"a": 2
} |
Yeah. But something like
That's the same in the
Yes, but that could be a
Yeah, I think inlining is not a strict requirement at all times. But there are cases where it's very helpful. So we should ideally have queries that would allow whoever is writing the function to make it inlineable. We can't control what is inside the function, but we can control how we call it, which affects inlineability, too. |
IMHO, allowing or denying the scalar functions used as computed relationship is more like a matter of taste. Inling a scalar function for If the desicion is to allow using the scalar functions as computed relationship, there is a subtlety between a scalar function and a
Notice the difference of the last row (because a set-returning function returns empty results and a scalar function returns a null row). An inner-join makes the case trickier:
|
Fixes PostgREST#2481 Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
Fixes PostgREST#2481 Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
Fixes PostgREST#2481 Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
Fixes #2481 Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
With the fixture
and the functions
If we want a rowtype-returning scalar function used as a computed relationship, my suggestion would be marking it as in
rows 1
, because such a function always returns one row, no more, no less.Originally posted by @Iced-Sun in #2475 (comment)
The text was updated successfully, but these errors were encountered: