SELECT question

Started by Brian Avisabout 23 years ago7 messagesgeneral
Jump to latest
#1Brian Avis
brian.avis@searhc.org

I want to run a SELECT on a text field and match any of the following.

brian
Brian
BRIAN

Or any other combination. How do I tell SQL to ignore case when doing
a SELECT?

--
Brian Avis
SEARHC Medical Clinic
Juneau, AK 99801
(907) 463-4049
Have a nice diurnal anomaly!

#2Brian Avis
brian.avis@searhc.org
In reply to: Brian Avis (#1)
Re: SELECT question

Assuming the data in the text field will resemble any of the following.

Brian K. Avis
Brian Avis
Brian

Or whatever combo.

Brian Avis wrote:

I want to run a SELECT on a text field and match any of the following.

brian
Brian
BRIAN

Or any other combination. How do I tell SQL to ignore case when
doing a SELECT?

--
Brian Avis
SEARHC Medical Clinic
Juneau, AK 99801
(907) 463-4049
Have a nice diurnal anomaly!

#3scott.marlowe
scott.marlowe@ihs.com
In reply to: Brian Avis (#2)
Re: SELECT question

On Thu, 30 Jan 2003, Brian Avis wrote:

Assuming the data in the text field will resemble any of the following.

Brian K. Avis
Brian Avis
Brian

Or whatever combo.

Brian Avis wrote:

I want to run a SELECT on a text field and match any of the following.

brian
Brian
BRIAN

Or any other combination. How do I tell SQL to ignore case when
doing a SELECT?

IF you're running 7.3.x, then you might need to use a tardis to go back in
time and make sure you used the C locale when you initdb'd your database.
If you didn't do that, then you'll need to backup your database and
reinitdb it with the C locale, then reload your data to make this work.
If you're on 7.2 and before, you won't have to reload your data to make
this next bit work...

Use a select with ilike:

select * from table where field ilike '%brian%';

should work.

#4scott.marlowe
scott.marlowe@ihs.com
In reply to: Brian Avis (#2)
Re: SELECT question

On Thu, 30 Jan 2003, Brian Avis wrote:

Assuming the data in the text field will resemble any of the following.

Brian K. Avis
Brian Avis
Brian

Or whatever combo.

Brian Avis wrote:

I want to run a SELECT on a text field and match any of the following.

brian
Brian
BRIAN

Or any other combination. How do I tell SQL to ignore case when
doing a SELECT?

the other method, which I forgot to add to my previous post is to user
lower()

select * from table where lower(name) like '%bruce%';

#5Brian Avis
brian.avis@searhc.org
In reply to: Brian Avis (#1)
Re: SELECT question

That did it. Thanks.

Devrim GUNDUZ wrote:

Hi,

On Fri, 2003-01-31 at 01:11, Brian Avis wrote:

I want to run a SELECT on a text field and match any of the following.

brian
Brian
BRIAN

Or any other combination. How do I tell SQL to ignore case when doing
a SELECT?

SELECT * FROM table WHERE column ILIKE 'brian%';

should work.

Best regards,
--
Devrim GUNDUZ
www.gunduz.org

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

--
Brian Avis
SEARHC Medical Clinic
Juneau, AK 99801
(907) 463-4049
Have a nice diurnal anomaly!

#6Devrim GUNDUZ
devrim@tr.net
In reply to: Brian Avis (#1)
Re: SELECT question

Hi,

On Fri, 2003-01-31 at 01:11, Brian Avis wrote:

I want to run a SELECT on a text field and match any of the following.

brian
Brian
BRIAN

Or any other combination. How do I tell SQL to ignore case when doing
a SELECT?

SELECT * FROM table WHERE column ILIKE 'brian%';

should work.

Best regards,
--
Devrim GUNDUZ
www.gunduz.org

#7Medi Montaseri
medi.montaseri@intransa.com
In reply to: scott.marlowe (#4)
Re: SELECT question

You can also use regular expression (which I am very happy to see PG has
adopted).

You can say

select whatever from whereever where something ~* 'brian';

The style is very similar to Perl's adoption of Regular Expression, its
called
Learn-Once-Use-Many.....

See page 77 of "PostgreSQL Developer's Handbook, SAMS" or your nearest
PG web page.

scott.marlowe wrote:

Show quoted text

On Thu, 30 Jan 2003, Brian Avis wrote:

Assuming the data in the text field will resemble any of the following.

Brian K. Avis
Brian Avis
Brian

Or whatever combo.

Brian Avis wrote:

I want to run a SELECT on a text field and match any of the following.

brian
Brian
BRIAN

Or any other combination. How do I tell SQL to ignore case when
doing a SELECT?

the other method, which I forgot to add to my previous post is to user
lower()

select * from table where lower(name) like '%bruce%';

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org