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 EDBD1D1B8BC for ; Mon, 18 Aug 2003 20:13:01 -0300 (ADT) 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 99361-10 for ; Mon, 18 Aug 2003 20:12:54 -0300 (ADT) Received: from davinci.ethosmedia.com (unknown [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id F2E6AD1B8A1 for ; Mon, 18 Aug 2003 20:12:50 -0300 (ADT) Received: from [216.135.165.74] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3524968; Mon, 18 Aug 2003 16:13:16 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: "Moonstruck" , pgsql-sql@postgresql.org Subject: Re: Reverse pattern match. Date: Mon, 18 Aug 2003 16:11:27 -0700 User-Agent: KMail/1.4.3 References: <3f407aa4$0$15136$afc38c87@news.optusnet.com.au> In-Reply-To: <3f407aa4$0$15136$afc38c87@news.optusnet.com.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200308181611.27937.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/210 X-Sequence-Number: 14826 Moonstruck, > 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); PostgreSQL supports real Regular Expressions, via the ~ operator. See "~"= =20 under "functions and operators", and then consult your favorite book or=20 online ressouce on how to compose regexps.=20 An example of "is not in 415 area code" would be phone_no ~ '^415\d{7}'=20 which should be "415" at the beginning followed by at least 7 other digits. (Folks, please correct my regex code if it's bad!) The disadvantage to this approach is that it cannot be indexed.=20=20 --=20 -Josh Berkus Aglio Database Solutions San Francisco