2

I am trying to cast a list of strings to a list of custom enum types. The effect I am looking for can be achieved with this:

select * from table_1 where column_a in (cast('ENUM1' AS custom_enum), cast('ENUM2' AS custom_enum))

But since I am attempting this to bypass some JPA/hibernate issues I am having with annotated filters on sql enum types, I need to dynamically add the enum strings to the list. So I am trying to figure out how to cast a whole list of strings to a list of enum_types. I'm guessing something like this:

select * from table_1 where column_a in (cast({'ENUM1', 'ENUM2'} AS custom_enum[]))

But not much I have tried gives me any luck.

1 Answer 1

3

Use = ANY instead of IN. The array literal should be enclosed in quotes:

select * 
from table_1 
where column_a = any (cast('{ENUM1, ENUM2}' as custom_enum[]))

or cast the column to text:

select * 
from table_1 
where column_a::text in ('ENUM1', 'ENUM2')
Sign up to request clarification or add additional context in comments.

1 Comment

That's it! Looks like hibernate filtering doesn't like it unfortunately but thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.