Re: Isnumeric function?

From: Theo Galanakis <Theo(dot)Galanakis(at)lonelyplanet(dot)com(dot)au>
To: 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Isnumeric function?
Date: 2004-09-09 00:02:54
Message-ID: 82E30406384FFB44AFD1012BAB230B55037D057C@shiva.au.lpint.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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(at)sss(dot)pgh(dot)pa(dot)us]
Sent: Thursday, 9 September 2004 9:57 AM
To: Theo Galanakis
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Isnumeric function?

Theo Galanakis <Theo(dot)Galanakis(at)lonelyplanet(dot)com(dot)au> 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.

Browse pgsql-sql by date

  From Date Subject
Next Message Terence Kearns 2004-09-09 01:43:33 check for circular references in a 2-table heirachy
Previous Message Tom Lane 2004-09-08 23:57:20 Re: Isnumeric function?