Skip to main content
added 62 characters in body
Source Link
Cepr0
  • 31.1k
  • 9
  • 82
  • 105

Instead of IN we can use ANY with arrays casted to enum array, for example:

create tabletype example_tableexample_enum as enum (
--  'ENUM1', 'ENUM2'
);

create table example_table enum_field(
 example_enum id integer,
--  enum_field example_enum
);

select 
  * 
from 
  example_table t
where
  t.enum_field = any(array['ENUM1', 'ENUM2']::example_enum[]);

Or we can still use 'IN' clause, but first, we should 'unnest' it:

select 
  * 
from 
  example_table t 
where 
  t.enum_field in (select unnest(array['ENUM1', 'ENUM2']::example_enum[]));

Example: https://www.db-fiddle.com/f/LaUNi42HVuL2WufxQyEiC/0

Instead of IN we can use ANY with arrays casted to enum array, for example:

create table example_table (
-- 
   enum_field example_enum,
-- 
);

select 
  * 
from 
  example_table
where
  enum_field = any(array['ENUM1', 'ENUM2']::example_enum[]);

Or we can still use 'IN' clause, but first, we should 'unnest' it:

select 
  * 
from 
  example_table t 
where 
  t.enum_field in (select unnest(array['ENUM1', 'ENUM2']::example_enum[]));

Instead of IN we can use ANY with arrays casted to enum array, for example:

create type example_enum as enum (
  'ENUM1', 'ENUM2'
);

create table example_table (
  id integer,
  enum_field example_enum
);

select 
  * 
from 
  example_table t
where
  t.enum_field = any(array['ENUM1', 'ENUM2']::example_enum[]);

Or we can still use 'IN' clause, but first, we should 'unnest' it:

select 
  * 
from 
  example_table t
where
  t.enum_field in (select unnest(array['ENUM1', 'ENUM2']::example_enum[]));

Example: https://www.db-fiddle.com/f/LaUNi42HVuL2WufxQyEiC/0

added 97 characters in body
Source Link
Cepr0
  • 31.1k
  • 9
  • 82
  • 105

To use an enum array in the 'IN' clauseInstead of IN we should cast the passed array ascan use ANY with arrays casted to enum array then 'unnest' it, for example:

Table:

create table example_table (
-- 
   enum_field example_enum,
-- 
);

select 
  * 
from 
  example_table
where
  enum_field = any(array['ENUM1', 'ENUM2']::example_enum[]);

QueryOr we can still use 'IN' clause, but first, we should 'unnest' it:

select 
  * 
from 
  example_table t 
where 
  t.enum_field in (select unnest(array['ENUM1', 'ENUM2']::example_enum[]));

sqlfiddle

To use an enum array in the 'IN' clause we should cast the passed array as enum array then 'unnest' it, for example:

Table:

create table example_table (
-- 
   enum_field example_enum,
-- 
);

Query:

select 
  * 
from 
  example_table t 
where 
  t.enum_field in (select unnest(array['ENUM1', 'ENUM2']::example_enum[]));

sqlfiddle

Instead of IN we can use ANY with arrays casted to enum array, for example:

create table example_table (
-- 
   enum_field example_enum,
-- 
);

select 
  * 
from 
  example_table
where
  enum_field = any(array['ENUM1', 'ENUM2']::example_enum[]);

Or we can still use 'IN' clause, but first, we should 'unnest' it:

select 
  * 
from 
  example_table t 
where 
  t.enum_field in (select unnest(array['ENUM1', 'ENUM2']::example_enum[]));
Source Link
Cepr0
  • 31.1k
  • 9
  • 82
  • 105

To use an enum array in the 'IN' clause we should cast the passed array as enum array then 'unnest' it, for example:

Table:

create table example_table (
-- 
   enum_field example_enum,
-- 
);

Query:

select 
  * 
from 
  example_table t 
where 
  t.enum_field in (select unnest(array['ENUM1', 'ENUM2']::example_enum[]));

sqlfiddle