pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Moonstruck <bogus.email@pls-relpy-to.group>
To: pgsql-sql@postgresql.org
Subject: Re: Reverse pattern match.
Date: Wed, 20 Aug 2003 16:42:30 +1000
Message-ID: <3f431856$0$15134$afc38c87@news.optusnet.com.au> (raw)
References: <3f407aa4$0$15136$afc38c87@news.optusnet.com.au>
	<200308181611.27937.josh@agliodbs.com>

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@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 Berkus
 Aglio Database Solutions
 San Francisco


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html






view thread (4+ messages)

Message-ID: <3f431856$0$15134$afc38c87@news.optusnet.com.au>
Permalink:  ../3f431856$0$15134$afc38c87@news.optusnet.com.au/
Also on:    postgresql.org/message-id/3f431856$0$15134$afc38c87@news.optusnet.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bogus.email@pls-relpy-to.group
  Subject: Re: Reverse pattern match.
  In-Reply-To: <3f431856$0$15134$afc38c87@news.optusnet.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox