Re: Pattern Matching - Range of Letters

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Ron St-Pierre <ron(dot)pgsql(at)shaw(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Pattern Matching - Range of Letters
Date: 2007-05-10 19:35:19
Message-ID: 464373F7.40100@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ron St-Pierre wrote:
> I'm sure that others have solved this but I can't find anything with my
> (google and archive) searches. I need to retrieve data where the text
> field is within a certain range e.g.
> A-An
> Am-Bc
> Bc-Eg
> ....
> Yi-Zz
>
> Does anyone know of a good approach to achieve this? Should I be looking
> into regular expressions, or maybe converting them to their ascii value
> first?

postgres=# create table test (test text);
CREATE TABLE
postgres=# insert into test values ('A');
INSERT 0 1
postgres=# insert into test values ('b');
INSERT 0 1
postgres=# insert into test values ('c');
INSERT 0 1
postgres=# insert into test values ('d');
INSERT 0 1
postgres=# insert into test values ('e');
INSERT 0 1
postgres=# insert into test values ('Ab');
INSERT 0 1
postgres=# insert into test values ('Ac');
INSERT 0 1
postgres=# insert into test values ('Az');
INSERT 0 1
postgres=# select * from test where test between 'A' and 'An';
test
------
A
Ab
Ac
(3 rows)

>
> Any comments are appreciated.
>
> postgres 8.2.4, RHEL
>
> Thanks
> Ron St.Pierre
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

--

=== The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive PostgreSQL solutions since 1997
http://www.commandprompt.com/

Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron St-Pierre 2007-05-10 19:53:56 Re: Pattern Matching - Range of Letters
Previous Message Richard Broersma Jr 2007-05-10 19:33:49 Re: Pattern Matching - Range of Letters