From: | xach(at)xach(dot)com (Zachary Beane) |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: is_numeric() or extract_numeric() functions? |
Date: | 2003-01-29 03:01:35 |
Message-ID: | slrnb3eh1b.8k3.xach@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Ron St.Pierre wrote:
> I can't find an is_numeric() or extract_numeric() function in postgres
> so I decided I would make my own. However, when I try to create the
> following function:
>
>
> CREATE OR REPLACE FUNCTION getnumber(varchar(1)) RETURNS integer AS '
> BEGIN
> return ($1 ~ '[0-9]');
> END;
> ' LANGUAGE 'plpgsql';
>
>
> I get the following error:
>
> parse error at or near "["
>
>
> Anyone know how to fix this, or if there is an is_numeric() or
> extract_numeric() function available?
Your error is caused by including a bare single-quote inside the
function, which is itself single-quoted. You need to escape the single
quote:
CREATE OR REPLACE FUNCTION getnumber(varchar(1)) RETURNS integer AS '
BEGIN
return ($1 ~ ''[0-9]'');
END;
' LANGUAGE 'plpgsql';
That should do the trick.
Zach
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Kings-Lynne | 2003-01-29 03:01:46 | Re: stopping access to a database |
Previous Message | Tom Lane | 2003-01-29 02:20:52 | Re: 7.3 LOCK TABLE problem |