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 D6B6C329D22 for ; Thu, 9 Sep 2004 00:57:34 +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 88389-07 for ; Wed, 8 Sep 2004 23:57:23 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id DAAA6329C7B for ; Thu, 9 Sep 2004 00:57:23 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i88NvLoc026301; Wed, 8 Sep 2004 19:57:21 -0400 (EDT) To: Theo Galanakis Cc: pgsql-sql@postgresql.org Subject: Re: Isnumeric function? In-reply-to: <82E30406384FFB44AFD1012BAB230B55037D057B@shiva.au.lpint.net> References: <82E30406384FFB44AFD1012BAB230B55037D057B@shiva.au.lpint.net> Comments: In-reply-to Theo Galanakis message dated "Thu, 09 Sep 2004 09:39:15 +1000" Date: Wed, 08 Sep 2004 19:57:20 -0400 Message-ID: <26300.1094687840@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/53 X-Sequence-Number: 18899 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