-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Raise when empty list is given to values/2
#4523
Raise when empty list is given to values/2
#4523
Conversation
I think it would be great to mention this in docs as well. It is not obvious that empty list must be handled explicitly. I caught this error in production. |
@fuelen Thank you that's a good callout. I will update the docs. Out of curiosity do you know of any other standard way that this is handled? |
If we talk about elegant ways, then I don't know any |
Ok I'll merge it this way since I wasn't able to find a way to represent an empty values list. If that changes I'll submit a PR to the adapters to change the SQL. Thank you for the report. |
I have asked chatgpt and it suggested generating |
It will work, but it is no longer a VALUES statement 🙂 Don't know whether this is a problem. SELECT * FROM (SELECT NULL::uuid, NULL::text, NULL::int WHERE false) AS v1 ("id", "name", "age") |
I don't think it is a problem in this case, but maybe @greg-rychlewski disagrees. :) |
I think it could be a bit jarring to see such a different query in the logs if you're investigating unexpected input. But I also agree it is not good that it raises. Since I can't think of anything better then I would go with it because I agree raising is the worst option. |
@josevalim is it really wise to send that along the connection and wait for the db to respond though? |
It could be part of a left join like this select * from test left join (select null where false) as n on true; |
I am still a bit unsure but after thinking about it more, it might not be so bad to let the query go through and then raise at the driver level. My reasoning:
Probably point 2 is the most contentious because sometimes Ecto helps and sometimes it doesn't. In this case I could see a case for saying "ok you asked for an empty list, you got it". Similar to if you ask not a non-existent table. If we go this route then I still to clean up the SQL because we have some issues like missing types. |
Any route is fine by me. 👍 |
Closes #4522