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

function exception

From: "Wright, George" <George(dot)Wright(at)infimatic(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: function exception
Date: 2008-05-06 14:23:55
Message-ID: 51548D6D5BEB57468163194A8C1A0E98C6BA6A@MAGPTCPEXC02.na.mag-ias.net (view raw or flat)
Thread:
Lists: pgsql-novice
While writing a date validation function, I'm not sure which condition
to check for in the following exception handler.

 

 

CREATE OR REPLACE FUNCTION IsValidDateTime(timestamp with time zone)
RETURNS BOOLEAN AS $$

  BEGIN

    PERFORM CAST($1 AS TIMESTAMP WITH TIME ZONE); 

    RETURN TRUE;

  EXCEPTION WHEN INVALID_DATETIME_FORMAT THEN

    RETURN FALSE;

  END

$$ LANGUAGE 'plpgsql';

 

 

If I call it this way:   SELECT IsValidDateTime('2008-05-06 00:00:95');


 

I would expect it to return FALSE but it returns:

ERROR:  date/time field value out of range: "2008-05-06 00:00:95"

 

Is there either a specific error code to use or is there a generic catch
all code? I didn't see anything better listed at
http://www.postgresql.org/docs/8.0/static/errcodes-appendix.html

 

Thanks.

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2008-05-06 14:45:11
Subject: Re: function exception
Previous:From: Tom LaneDate: 2008-05-06 01:08:25
Subject: Re: Problem with Trigger

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