Re: How to trap invalid enum input exception?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Leon Starr <leon_starr(at)modelint(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: How to trap invalid enum input exception?
Date: 2010-08-16 03:12:02
Message-ID: 11818.1281928322@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Leon Starr <leon_starr(at)modelint(dot)com> writes:
> db=# select test_input('blue');
> ERROR: invalid input value for enum side: "blue"

> 1) What is the actual name of the condition (and, yes, I looked through appendix A trying to figure it out) for invalid enum input?

[ looks at code... ] Try INVALID_TEXT_REPRESENTATION.

> 2) Is there a way to retrieve the error code so that I don't have to guess at the condition name? (I've been playing this game a lot with other exceptions and I don't understand WHY the condition or code isn't provided when an untrapped error occurs) Clearly, I'm missing something!

In psql, you can do this:

regression=# CREATE TYPE side AS ENUM ('right', 'left');
CREATE TYPE
regression=# select 'blue'::side;
ERROR: invalid input value for enum side: "blue"
LINE 1: select 'blue'::side;
^
regression=# \set VERBOSITY verbose
regression=# select 'blue'::side;
ERROR: 22P02: invalid input value for enum side: "blue"
LINE 1: select 'blue'::side;
^
LOCATION: enum_in, enum.c:56

and after that, you can either look up the SQLSTATE 22P02 in appendix A,
or consult the source code in enum_in(). If you're not using psql, the
same information should be available through the client API you're using
--- feel free to complain to its authors if not.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Leon Starr 2010-08-16 03:53:50 Re: How to trap invalid enum input exception?
Previous Message Leon Starr 2010-08-16 02:11:05 How to trap invalid enum input exception?