X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id EDF5AD1B8B5 for ; Mon, 18 Aug 2003 07:20:17 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 40391-05 for ; Mon, 18 Aug 2003 04:20:07 -0300 (ADT) Received: from news.hub.org (unknown [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id 5C150D1B8A5 for ; Mon, 18 Aug 2003 04:20:06 -0300 (ADT) Received: from news.hub.org (host-64-117-224-194.altec1.com [64.117.224.194] (may be forged)) by news.hub.org (8.12.9/8.12.9) with ESMTP id h7I7K6ek089668 for ; Mon, 18 Aug 2003 07:20:06 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h7I7ABvi088069 for pgsql-sql@postgresql.org; Mon, 18 Aug 2003 07:10:11 GMT From: "Moonstruck" X-Newsgroups: comp.databases.postgresql.sql Subject: Reverse pattern match. Date: Mon, 18 Aug 2003 17:05:10 +1000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 Lines: 25 Message-ID: <3f407aa4$0$15136$afc38c87@news.optusnet.com.au> To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/208 X-Sequence-Number: 14824 I want to create a table of regular expression patterns (for assessing phone numbers), something like: CREATE TABLE CallType ( pattern varchar primary key, type varchar, rate int4); INSERT INTO CallType VALUES ('0[3-9]________','Interstate Call',50); INSERT INTO CallType VALUES ('9_______','Local Call',25); INSERT INTO CallType VALUES ('0011__________%','International Call',100); Then determine call types, based on a match, something like: PhoneNumber := '99116633'; SELECT type, rate FROM CallType where pattern LIKE PhoneNumber; (Sorry about the pseudo-code), but you get the gist. The query returns a calltype description and a call rate based on the comparison of the actual phone-number to a table of RE patterns. I can't get my head around a way to do this, can anyone help? Guy