From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | "Moonstruck" <bogus(dot)email(at)pls-relpy-to(dot)group>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Reverse pattern match. |
Date: | 2003-08-18 23:11:27 |
Message-ID: | 200308181611.27937.josh@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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 "~"
under "functions and operators", and then consult your favorite book or
online ressouce on how to compose regexps.
An example of "is not in 415 area code" would be
phone_no ~ '^415\d{7}'
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.
--
-Josh Berkus
Aglio Database Solutions
San Francisco
From | Date | Subject | |
---|---|---|---|
Next Message | Vernon Smith | 2003-08-19 03:59:34 | Inheritance or no inheritance, there is a question |
Previous Message | Rod Taylor | 2003-08-18 23:05:35 | Re: Reverse pattern match. |