"PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> writes:
> Description: create domain strange behaviour
IIRC, plpgsql is not yet domain-aware and won't check constraints
associated with domain values. I'd suggest declaring
generate_session_id() to return plain text, so that the domain coercion
and constraint test happen after the function returns.
Yes, this is a bug in plpgsql, but it's not going to get fixed right
away.
regards, tom lane