简体   繁体   中英

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.

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

Just use a string literal :

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

Or:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM