I have the ENUM type in postgresql
CREATE TYPE user_state AS ENUM (\'unconfirmed\', \'locked\', \'active\');
<
Alternatively you may register equal operator instead of define cast
one. I did it for Java
+ MyBatis
in similar situation:
CREATE FUNCTION type_user_state_with_text_equals(_a user_state, _b text)
RETURNS boolean AS
$func$
SELECT _a = _b::user_state;
$func$
LANGUAGE SQL IMMUTABLE STRICT;
CREATE OPERATOR = (
leftarg = user_state,
rightarg = text,
procedure = type_user_state_with_text_equals,
COMMUTATOR = =,
NEGATOR = !=,
HASHES, MERGES
);
You may read about postgres user-defined operations in documentation and do not forget look at optimization hints.