X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4C571329D62 for ; Thu, 9 Sep 2004 01:05:56 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91852-02 for ; Thu, 9 Sep 2004 00:05:48 +0000 (GMT) Received: from angel.lonelyplanet.com.au (mail.lonelyplanet.com.au [202.147.44.168]) by svr1.postgresql.org (Postfix) with ESMTP id D1C2E329D14 for ; Thu, 9 Sep 2004 01:05:49 +0100 (BST) Received: from shiva.au.lpint.net ([192.168.61.22]) by angel with InterScan Messaging Security Suite; Thu, 09 Sep 2004 10:02:55 +1000 Received: by shiva.au.lpint.net with Internet Mail Service (5.5.2656.59) id ; Thu, 9 Sep 2004 10:02:59 +1000 Message-ID: <82E30406384FFB44AFD1012BAB230B55037D057C@shiva.au.lpint.net> From: Theo Galanakis To: 'Tom Lane' Cc: pgsql-sql@postgresql.org Subject: Re: Isnumeric function? Date: Thu, 9 Sep 2004 10:02:54 +1000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2656.59) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C49600.5B2ABB30" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.0 tagged_above=0.0 required=5.0 tests=DNS_FROM_RFCI_DSN, EXCUSE_16, HTML_20_30, HTML_MESSAGE X-Spam-Level: ** X-Archive-Number: 200409/54 X-Sequence-Number: 18900 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C49600.5B2ABB30 Content-Type: text/plain 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:tgl@sss.pgh.pa.us] Sent: Thursday, 9 September 2004 9:57 AM To: Theo Galanakis Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Isnumeric function? Theo Galanakis 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. ------_=_NextPart_001_01C49600.5B2ABB30 Content-Type: text/html Content-Transfer-Encoding: quoted-printable RE: [SQL] Isnumeric function?

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

Theo

-----Original Message-----
From: Tom Lane [mai= lto:tgl@sss.pgh.pa.us]
Sent: Thursday, 9 September 2004 9:57 AM
To: Theo Galanakis
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Isnumeric function?


Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>= writes:
> So I came up with the following. A Insert/update tr= igger 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 := =3D NEW.content;
>   ELSE
>      NEW.content_numeric := =3D null;

Hmm.  Seems like you could get burnt by "conten= t" 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 m= ake an assumption that indexable keys are at most 9 digits?  If so the= n

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

             = ;           reg= ards, 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 in= tended recipient of this email, you must not
use, copy or disclose its c= ontent to anyone. You must not copy or
communicate to others content t= hat is confidential or subject to
copyright, unless you have the consen= t of the content owner.
------_=_NextPart_001_01C49600.5B2ABB30--