Lists: | pgsql-sql |
---|
From: | "Moonstruck" <bogus(dot)email(at)pls-relpy-to(dot)group> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Reverse pattern match. |
Date: | 2003-08-18 07:05:10 |
Message-ID: | 3f407aa43f407aa4$0$15136$afc38c87@news.optusnet.com.au136$afc38c87@news.optusnet.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | 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
From: | Rod Taylor <rbt(at)rbt(dot)ca> |
---|---|
To: | Moonstruck <bogus(dot)email(at)pls-relpy-to(dot)group> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Reverse pattern match. |
Date: | 2003-08-18 23:05:35 |
Message-ID: | 1061247934.33964.1.camel@jester |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
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;
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 |
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: | "Moonstruck" <bogus(dot)email(at)pls-relpy-to(dot)group> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Reverse pattern match. |
Date: | 2003-08-20 06:42:30 |
Message-ID: | 3f4318563f431856$0$15134$afc38c87@news.optusnet.com.au134$afc38c87@news.optusnet.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
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 a C 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(at)agliodbs(dot)com> wrote in message
news:200308181611(dot)27937(dot)josh(at)agliodbs(dot)com(dot)(dot)(dot)
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
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
From: | Drew Wilson <amw(at)speakeasy(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | logging messages from inside pgPLSQL routine? |
Date: | 2003-08-22 00:21:47 |
Message-ID: | 9E11790C-D436-11D7-A9F2-000393D3E482@speakeasy.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
I'mm trying to debug something inside my PLSQL routine. How do I print
out error messages from inside my function?
Thanks,
Drew
From: | Roberto Mello <rmello(at)cc(dot)usu(dot)edu> |
---|---|
To: | Drew Wilson <amw(at)speakeasy(dot)net> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: logging messages from inside pgPLSQL routine? |
Date: | 2003-08-22 01:21:30 |
Message-ID: | 20030822012130.GB9496@cc.usu.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
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...