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 $$
PERFORM CAST($1 AS TIMESTAMP WITH TIME ZONE);
EXCEPTION WHEN INVALID_DATETIME_FORMAT THEN
$$ 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