Re: Error handling inside PL/pgSQL functions - Mailing list pgsql-general

From Tony Caduto
Subject Re: Error handling inside PL/pgSQL functions
Date
Msg-id 452EA3EA.3010206@amsoftwaredesign.com
Whole thread Raw
In response to Error handling inside PL/pgSQL functions  ("Germán Hüttemann Arza" <ghuttemann@gmail.com>)
Responses Re: Error handling inside PL/pgSQL functions  (Jeff Davis <pgsql@j-davis.com>)
List pgsql-general
Germán Hüttemann Arza wrote:
> I am writing triggers procedures in PL/pgSQL and I need to handle some
> errors inside the procedures.
> Specifically, I am doing a CAST(char AS integer) and I want to know
> when the char isn't a digit. How can I get do that?
>
Just off the top of my head I would say you could use a regular
expression to check if the char is numeric value.

something like this maybe:

CREATE or REPLACE FUNCTION public.isnumeric(
text)
RETURNS pg_catalog.bool AS
$BODY$
SELECT $1 ~ '^[0-9]*(.[0-9]+)?$'
$BODY$
LANGUAGE 'sql' VOLATILE;

You might have to modify the regular expression a bit as I was using it
to test for doubles not just integers.


--
Tony Caduto
AM Software Design
http://www.amsoftwaredesign.com
Home of PG Lightning Admin for Postgresql
Your best bet for Postgresql Administration


pgsql-general by date:

Previous
From: Wei Weng
Date:
Subject: Re: Question on MD5 authentication
Next
From: "Jim C. Nasby"
Date:
Subject: Re: more anti-postgresql FUD