Skip to content

How to use a enum in CASE statement (operator) and cast the statement to the correct type? #409

Answered by go-jet
robertgroh asked this question in Q&A
Discussion options

You must be logged in to vote

Since both case branches return type of registration_state, you don't need to add SQL cast. All you have to do is satisfy go compiler, by wrapping stateCaseOperator to StringExp:

Registrations.State.SET(StringExp(stateCaseOperator)),

In case all branches do not return the same type, you can add the sql enum cast first and than sql builder wrapper cast:

stateCast := StringExp(CAST(stateCaseOperator).AS("<schema_name>.registration_state"))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@robertgroh
Comment options

Answer selected by robertgroh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants