user3401335
user3401335

Reputation: 2405

How use enum in postgres

I have created an enum type in Postgres:

CREATE TYPE myenum AS ENUM ('a', 'b', 'c', 'd');

I have created a function:

CREATE OR REPLACE FUNCTION public.mystore(type myenum)

Now in the stored procedure how I can check if a type is 'a' or 'b' like

if(type = myenum.a or type =  myenum.b) then
   ...
end if;

In fact the last line of code is not working.

Upvotes: 2

Views: 190

Answers (2)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 658492

Just use a string literal:

WHERE type = 'a' OR type = 'b'

Or:

WHERE type IN ('a', 'b')

Upvotes: 2

Kouber Saparev
Kouber Saparev

Reputation: 8125

IF (type = 'a' OR type = 'b') THEN
  ...
END IF;

Upvotes: 3

Related Questions