Title: RE: [SQL] Isnumeric function?

Thanks Tom,
Actually I did not attach the latest function, I did have a limit of 9 numerical characters, found that out when I applied the update to move all current numerical values to that column.

Theo

-----Original Message-----
From: Tom Lane [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 9 September 2004 9:57 AM
To: Theo Galanakis
Cc: [EMAIL PROTECTED]
Subject: Re: [SQL] Isnumeric function?


Theo Galanakis <[EMAIL PROTECTED]> writes:
> So I came up with the following. A Insert/update trigger would call a
> procedure to check to see if the content is numeric(a whole number),
> if so would update an indexed integer column called (content_numeric).
> Which would be the base column to search appon.

> CREATE OR REPLACE FUNCTION update_content_node()
>   RETURNS trigger AS
> '
> begin
>   /* New function body */
>   IF NEW.content ~ \'^[0-9]+$\' THEN
>      NEW.content_numeric := NEW.content;
>   ELSE
>      NEW.content_numeric := null;

Hmm.  Seems like you could get burnt by "content" that is by chance a long string of digits --- you'd get an integer overflow error at the attempt to assign to content_numeric.  Can you make an assumption that indexable keys are at most 9 digits?  If so then

        IF NEW.content ~ \'^[0-9]{1,9}$\' THEN
Or use a bigint column and crank up the number of digits appropriately.

                        regards, tom lane

______________________________________________________________________
This email, including attachments, is intended only for the addressee
and may be confidential, privileged and subject to copyright. If you
have received this email in error, please advise the sender and delete
it. If you are not the intended recipient of this email, you must not
use, copy or disclose its content to anyone. You must not copy or
communicate to others content that is confidential or subject to
copyright, unless you have the consent of the content owner.

Reply via email to