Skip to content
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

RUNTIME error: DEFAULT not allowed in this context #744

Open
runebak opened this issue Feb 21, 2025 · 4 comments
Open

RUNTIME error: DEFAULT not allowed in this context #744

runebak opened this issue Feb 21, 2025 · 4 comments
Labels
breaking change Change will require a major version bump bug help wanted

Comments

@runebak
Copy link

runebak commented Feb 21, 2025

I'm using PostgresSQL and I wanted to update a column to the default value if it was NULL.
Beam happily accepts both
(\r -> coalesce_ [just_ $current_ r.column] default_)
and
(\r -> if_ [isNothing_ (current_ r.column) then_ default_] (else_ $ current_ r.column))

But coalesce(r.column,DEFAULT) is not valid sql.
I need to supply the default manually.
I didn't find the proper way for this in beam, as the default is current_timestamp but the column is timstamptz in postgres corresponding to UTCTime in Haskell, but now_ in Beam only works for LocalTime .
I got around it with using coerce_ now_ instead,
but this doesn't feel right as it seems that GHC will happily coerce ANY beam type to one another...

(I have also used this coerce trick to get out of Maybe/Nullable when selecting only not null rows, haven't found a good way for this either.)

@runebak
Copy link
Author

runebak commented Feb 21, 2025

I don't see an easy way to enforce not allowing default_ in there, but I don't know about the internal of beam either. Not a critical thing, but I just thought you liked to know!

@LaurentRDC LaurentRDC added the bug label Feb 21, 2025
@LaurentRDC
Copy link
Member

Thanks for the bug report! I will check it out as soon as I can.

I don't see an easy way to enforce not allowing default_ in there

The SQL AST is defined with a myriad of types and type classes, one of which might allow something it shouldn't. It might be as simple as tweaking one of those.

@LaurentRDC
Copy link
Member

LaurentRDC commented Feb 22, 2025

Reading a little bit more about coalesce and default in SQL, default can't be used as a function argument basically anywhere (at least in PostgreSQL).

@LaurentRDC
Copy link
Member

I thought about this a little more. It looks like default_ shouldn't be a general QExpr. There are more layers to the SQL syntax.
Fixing this would be a major breaking change. For now, I'll update the documentation of coalesce_ and other functions. Happy to review pull requests on this topic.

@LaurentRDC LaurentRDC added help wanted breaking change Change will require a major version bump labels Feb 23, 2025
LaurentRDC added a commit that referenced this issue Feb 23, 2025
LaurentRDC added a commit that referenced this issue Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Change will require a major version bump bug help wanted
Projects
None yet
Development

No branches or pull requests

2 participants