How to convert jsonb value to int and apply expression #1915
Replies: 2 comments 2 replies
-
JSONBInteger expects to be initialized with an integer value, not an arbitrary SQL expression. You probably want something like: Sequel.function(:coalesce, column["code1"], '0').cast_numeric + 1 |
Beta Was this translation helpful? Give feedback.
-
This produce slightly more verbose SQL than what was expected. So instead of I've stumbled into a last issue, where the 3rd parameter of (Sequel.function(:coalesce, column["code1"], '0').cast_numeric + 1).cast(:text).cast(:jsonb) And the query was executed, so success! Let me know if you still have thoughts about any of this, and thx again for the support! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi 👋 ,
I'm looking to generate a query to apply an atomic increment on a jsonb sql. This can be done with the following expression:
I came to the following sequel, which does not work fully yet:
Using the above does not work, and blows up with the following error:
This happens because the json column lookup isn't converted anymore via
::int
(byJSONInteger
). What's the correct way to do it in sequel?Moreover, if I remove the " + 1" part of the update expression, the query runs, but the result is wrong:
Beta Was this translation helpful? Give feedback.
All reactions