-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Incorrect type when using jsonb_agg #233
Comments
Thanks for the detailed reproduction. I'll look into it. |
Nice I forgot to include the data in the issue, here are inserts for the data I used to test this: insert into users (id, public_id, username, created_at, updated_at)
values (1, 'test', 'test', '2024-06-10 12:31:20.240877 +00:00', '2024-06-10 12:31:20.240877 +00:00');
insert into user_authentication_methods (id, user_id, name, data, created_at, updated_at)
values (1, 1, 'test1', '{"some_data": 123}', '2024-06-10 12:31:38.655757 +00:00', '2024-06-10 12:31:38.655757 +00:00'),
(2, 1, 'test2', '{"some_other_data": 321}', '2024-06-10 12:31:47.674517 +00:00', '2024-06-10 12:31:51.324642 +00:00'); |
I've been doing some debugging to see if I can fix this. I've ended up here, and realized that this inner type should be made nullable if the argument given to json_agg may be null (such as in the case of a LEFT JOIN in my case). I am checking this with I see that Also, detecting whether the value in the final selection can be null (e.g. in the case above where I use GROUP BY) would require a more sophisticated way of constructing I think it would make most sense to assume that jsonb_agg can contain null values whenever its argument is not the table in the FROM clause. Not 100% accurate but close enough I think |
This is somewhat related to #210 I have unstaged changes that attempts to solve this issue by introducing a new "group" node which can be "nullable" and contain "children". This is quite a fundamental change from the way I initially wrote the ast-describe part. Another required fundamental change would be to merge the non nullable columns logic with the descriptor, since sometimes it needs additional context. Once I have enough time keep working on it, I'll send some updates. In the meantime, feel free to explore this path. |
That's a nice approach. I think this wouldn't fully solve the GROUP BY causing any potentially null results from being omitted, but it is probably not even needed since you can just COALESCE to get rid of that null type |
Describe the bug
A clear and concise description of what the bug is.
When using jsonb_agg safeql is suggesting an incorrect TS type.
To Reproduce
Steps to reproduce the behavior:
DB setup:
Example of wrong type:
Expected behavior
A clear and concise description of what you expected to happen.
I would expect json_agg to have the type
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
Another bonus issue I found while playing around:
method is definitely not a number
The text was updated successfully, but these errors were encountered: