Reverse pattern match. - Mailing list pgsql-sql

From Moonstruck
Subject Reverse pattern match.
Date
Msg-id 3f407aa4$0$15136$afc38c87@news.optusnet.com.au
Whole thread Raw
Responses Re: Reverse pattern match.  (Rod Taylor <rbt@rbt.ca>)
Re: Reverse pattern match.  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
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





pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Expression transformation curiosity
Next
From: Rod Taylor
Date:
Subject: Re: Reverse pattern match.