circuithub / rel8

Hey! Hey! Can u rel8?
https://rel8.readthedocs.io
Other
150 stars 38 forks source link

`unsafeDefault` generates invalid sql for some queries where it should not #233

Closed abigailalice closed 3 months ago

abigailalice commented 1 year ago

I recently switched from Opaleye to Rel8, and noticed on inserts the unsafeDefault function generates invalid sql if the rows field is populated like rows = pure $ Row { key = unsafeDefault }, generating a DEFAULT is not allowed in this context error message.

Using rows = values [Row {key = unsafeDefault}] seems to fix the issue, so I assume it's an issue with Rel8 generating SQL with an explicit select statement in the pure case, but not with a trivial use of values. I don't know if that should be considered a bug or not, since it's already marked unsafe; it could arguably fall under the "DEFAULT values can not be transformed" caveat. But if it is considered an example of that, pure is probably still trivial enough to warrant that being explicitly stated in the documentation.

shane-circuithub commented 1 year ago

This is a known issue, DEFAULT can only INSERT statements that are built with VALUES. It's just how Postgres's syntax works. But you're right we should probably clarify this in the documentation.

abigailalice commented 3 months ago

This is now added to the documentation for unsafeDefault @shane-circuithub. Should this be left open in case anyone ever decided to rewrite the trivial inserts to prevent the actual issue? I'm fine with it being closed, considering how small an issue it is, and that the name already alerts people to check the docs.

ocharles commented 3 months ago

I think I'm OK with the status quo for now