建立函数:
CREATE OR REPLACE FUNCTION enumtest(anyenum) RETURNS text AS $$ SELECT $1::text; $$ LANGUAGE SQL;
建立enum:
pgsql=# CREATE TYPE ecolor AS ENUM ('white','green','blue'); CREATE TYPE pgsql=#
pgsql=# CREATE TYPE esize AS ENUM ('small','middle','big'); CREATE TYPE pgsql=#
使用函数:
pgsql=# select enumtest(ecolor('white')); enumtest ---------- white (1 row) pgsql=# select enumtest(ecolor('green')); enumtest ---------- green (1 row) pgsql=#
pgsql=# select enumtest(esize('middle')); enumtest ---------- middle (1 row) pgsql=#