简体   繁体   English

如何在postgres中使用枚举

[英]How use enum in postgres

I have created an enum type in Postgres: 我在Postgres中创建了一个enum类型:

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 现在在存储过程中我如何检查类型是'a'还是'b'

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 : 只需使用string literal

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

Or: 要么:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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