Unix Technical Forum

select a range of data

This is a discussion on select a range of data within the pgsql Admins forums, part of the PostgreSQL category; --> If I have a column with a value like "abc2457", "efg1234", how do I select col from table where ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Admins

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 08:48 AM
Jessica Richard
 
Posts: n/a
Default select a range of data

If I have a column with a value like "abc2457", "efg1234",

how do I select col from table where col like 'a[a-z]c24[0-9]7"?

How do I handle the range bracket in the query?

Thanks.


---------------------------------
Boardwalk for $500? In 2007? Ha!
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 08:48 AM
Tom Lane
 
Posts: n/a
Default Re: select a range of data

Jessica Richard <rjessil@yahoo.com> writes:
> how do I select col from table where col like 'a[a-z]c24[0-9]7"?
> How do I handle the range bracket in the query?


Using LIKE, you don't. However there are two other types of
pattern-matching operators that do understand character classes:

http://www.postgresql.org/docs/8.2/s...-matching.html

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 08:48 AM
Jon Sime
 
Posts: n/a
Default Re: select a range of data

Jessica Richard wrote:
> If I have a column with a value like "abc2457", "efg1234",
>
> how do I select col from table where col like 'a[a-z]c24[0-9]7"?
>
> How do I handle the range bracket in the query?


You can use the regular expression operator(s), like so:

select *
from table
where column ~ 'a[a-z]c24[0-9]7';

For the full details:
http://www.postgresql.org/docs/8.2/i...g.html#AEN9312

-Jon

--
Senior Systems Developer
Media Matters for America
http://mediamatters.org/

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:04 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com