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

Re: using position in where

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: using position in where
Date: 2009-11-16 07:50:51
Message-ID: hdr08r$6um$ (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On 2009-11-13, Lynn Manhart <ManhartL(at)mstarmetro(dot)net> wrote:
> I have an application where I need to "select" based on whether or not a 
> "text" column value contains a given substring. I have tried the "position" 
> function as follows, but it doesn't return anything:
> select * in customers where position ('sub_string' in 'text_column') > 0;
> Is there another way to do this?

select * FROM customers where position ('sub_string' in "text_column") > 0

perhaps using the like or ~ operators
 select * FROM customers where "text_column" LIKE '%sub_string%";
 select * FROM customers where "text_column" ~ 'sub_string";
these operatours apply some magic to the contents of substring so for
useful results care must be taken when preparing it.
> Another question - how are upper and lower case handled when using "order 
> by"? In my experimenting, it seems to be doing a case insensitive compare, 
> but the docs I've read seem to indicate otherwise.

depends on the locale setting, "C" will get you ordering by unicode
code point so 'A' < 'Z' < 'a' < 'z' < 'À' < 'Ý'

"EN-US" should get you "dictionary" ordering 

show lc_collate;

In response to

pgsql-novice by date

Next:From: richard terryDate: 2009-11-16 21:51:51
Subject: Adding or altering column comment
Previous:From: John DeSoiDate: 2009-11-13 03:57:42
Subject: Re: using position in where

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