pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Theo Galanakis <Theo.Galanakis@lonelyplanet.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: Isnumeric function?
Date: Wed, 08 Sep 2004 19:57:20 -0400
Message-ID: <26300.1094687840@sss.pgh.pa.us> (raw)
In-Reply-To: <82E30406384FFB44AFD1012BAB230B55037D057B@shiva.au.lpint.net>
References: <82E30406384FFB44AFD1012BAB230B55037D057B@shiva.au.lpint.net>

Theo Galanakis <Theo.Galanakis@lonelyplanet.com.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



view thread (29+ messages)  latest in thread

Message-ID: <26300.1094687840@sss.pgh.pa.us>
Permalink:  ../26300.1094687840@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/26300.1094687840@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Theo.Galanakis@lonelyplanet.com.au
  Subject: Re: Isnumeric function?
  In-Reply-To: <26300.1094687840@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox