Re: How to trap invalid enum input exception? - Mailing list pgsql-novice

From Tom Lane
Subject Re: How to trap invalid enum input exception?
Date
Msg-id 18006.1281980402@sss.pgh.pa.us
Whole thread Raw
In response to Re: How to trap invalid enum input exception?  (Leon Starr <leon_starr@modelint.com>)
Responses Re: How to trap invalid enum input exception?
List pgsql-novice
Leon Starr <leon_starr@modelint.com> writes:
> I've trimmed my example down to the bare minimum in hopes of solving the problem myself, but no luck.  Here's the
exactcode and console session: 

> create type side as enum ('right', 'left');

> create or replace function testinput(
>     p_units_align    side
> ) returns void as
> ....

> contracts=# select * from testinput('blue');
> ERROR:  22P02: invalid input value for enum side: "blue"
> LINE 1: select * from testinput('blue');
>                                 ^
> LOCATION:  enum_in, enum.c:57

Well, the point here is that the system has to convert 'blue' to a value
of type "side" before it ever invokes your function.  So there's no hope
of trapping that failure inside the function.

If you really want to do things this way, you can declare the function
as taking a text string, and cast from text to "side" within the
function's exception-trapping block.

            regards, tom lane

pgsql-novice by date:

Previous
From: Leon Starr
Date:
Subject: Re: How to trap invalid enum input exception?
Next
From: Pg Novice
Date:
Subject: Creating a second database on the same computer