Skip site navigation (1) Skip section navigation (2)

How to trap invalid enum input exception?

From: Leon Starr <leon_starr(at)modelint(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: How to trap invalid enum input exception?
Date: 2010-08-16 02:11:05
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Hi all, I have the following defined in my database:

CREATE TYPE side AS ENUM ('right', 'left');

And I've defined a function that with a parameter of this type.

CREATE OR REPLACE FUNCTION test_input ( p_side side ) ...

Now I test the function with an invalid value:

db=# select test_input('blue');
ERROR:  invalid input value for enum side: "blue"

I want to trap the exception in my function

I tried the obvious INVALID_INPUT_VALUE with no success.

Two questions:

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?

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!

As always, help or informative redirects muchly appreciated!

- Leon


pgsql-novice by date

Next:From: Tom LaneDate: 2010-08-16 03:12:02
Subject: Re: How to trap invalid enum input exception?
Previous:From: Rikard BosnjakovicDate: 2010-08-15 08:19:54
Subject: Re: Help with trigger

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group