I have a table column in Postgresql which has a data type of enum type. Now I am using a query like below to select data from the table.
SELECT ................. FROM ............ WHERE transaction = ?::operations.transactions;
I am passing this query to the PreparedStatement object of JAVA. It works fine when I pass any of the enum type as parameter in setString method of the PreparedStatement.
Now I want to ask that is it possible to send a string as parameter to setString method of the PreparedStatement so that I can get all the enum types in the ResultSet?
If it is not possible with this statement, how else could I change the query to get the desired result? Or any other strategy that I could use to get the desired result?
You can use any(array expression). Example:
create type color as enum('white', 'blue', 'green');
with the_data(a_color) as (
values ('white'::color), ('blue'), ('green')
)
select *
from the_data
where a_color = any(array['white', 'blue']::color[]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With