I'm trying to abstract away selecting a field from JSONB column in PostgreSQL. The syntax for the function is as follows:
(<jsonb_field> ->> '<name_of_the_field_to_extract>')::<class_of_the_object>
The part about ->>
is quite easy to achieve already with something like this:
> dbplyr::sql_expr(json_field %->>% data_field)
<SQL> json_field ->> data_field
However, I don't see a way to build the second part of the expression (::<class_of_the_object
) since there is support for infix and prefix functions, but not for postfix.
Is there something I'm missing or at least some hack that I can use (other than creating strings by hand) to achieve this functionality?