Skip site navigation (1) Skip section navigation (2)

Re: SELECT from a list

From: Jean-Luc Lachance <jllachan(at)sympatico(dot)ca>
To: Markus Bertheau <twanger(at)bluetwanger(dot)de>
Cc: Keith Gallant <keith(at)justhosting(dot)ca>, pgsql-sql(at)postgresql(dot)org
Subject: Re: SELECT from a list
Date: 2004-07-25 14:40:22
Message-ID: 4103C656.4070109@sympatico.ca (view raw or flat)
Thread:
Lists: pgsql-sql

Markus Bertheau wrote:

> В Вск, 25.07.2004, в 15:18, Keith Gallant пишет:
> 
>>Hello
>>
>>I am wondering if it is possible to use a SINGLE LIKE statement for a
>>selection from a list.
>>
>>For example: If I want to return all results that a phrase starts with a
>>number, can I make a call similar to the following:
>>
>>SELECT * FROM table WHERE phrase LIKE
>>{'0%','1%','2%','3%','4%','5%','6%','7%','8%','9%'};
>>
>>If not is there an easier way than having to call this:
>>
>>SELECT * FROM table WHERE phrase LIKE '0%' OR phrase LIKE '1%' OR phrase
>>LIKE '2%' OR phrase LIKE '3%' OR phrase LIKE '4%' OR phrase LIKE '5%' OR
>>phrase LIKE '6%' OR phrase LIKE '7%' OR phrase LIKE '8%' OR phrase LIKE
>>'9%';
> 
> 
> WHERE SUBSTRING(phrase FROM 1 FOR 1) IN ('0', '1', ....)


Better yet:

SELECT * FROM table WHERE phrase ~ '^[0-9]';

> 


In response to

Responses

pgsql-sql by date

Next:From: Markus BertheauDate: 2004-07-25 16:21:56
Subject: Re: SELECT from a list
Previous:From: Markus BertheauDate: 2004-07-25 13:56:20
Subject: Re: SELECT from a list

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group