Обсуждение: Reverse pattern match.
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
On Mon, 2003-08-18 at 03:05, Moonstruck wrote:
> 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;
SELECT type, rate FROM CallType WHERE PhoneNumber ~ pattern;
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 BerkusAglio Database SolutionsSan Francisco
Many thanks... got it now.
Example...
sox=# select * from regexpatt;pattern | description
---------+------------------------------------^b | starts with a B^a | starts with an A^c.*l$ | starts with
aC and ends with an L
(3 rows)
sox=# select description from regexpatt where 'bravo' ~ pattern; description
----------------starts with a B
(1 row)
sox=# select description from regexpatt where 'caramel' ~ pattern; description
------------------------------------starts with a C and ends with an L
(1 row)
"Josh Berkus" <josh@agliodbs.com> wrote in message
news:200308181611.27937.josh@agliodbs.com...
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 BerkusAglio Database SolutionsSan Francisco
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html
I'mm trying to debug something inside my PLSQL routine. How do I print out error messages from inside my function? Thanks, Drew
On Thu, Aug 21, 2003 at 05:21:47PM -0700, Drew Wilson wrote: > I'mm trying to debug something inside my PLSQL routine. How do I print > out error messages from inside my function? RAISE NOTICE ''Foobar is %'', foobar; Where "foobar" is a variable. The documentation mentions this in several places and examples. -Roberto -- +----| Roberto Mello - http://www.brasileiro.net/ |------+ + Computer Science Graduate Student, Utah State University + + USU Free Software & GNU/Linux Club - http://fslc.usu.edu/ + Compiling...Linking...Dialing Copyright Lawyer...