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
In response to
pgsql-novice by date
|Next:||From: richard terry||Date: 2009-11-16 21:51:51|
|Subject: Adding or altering column comment|
|Previous:||From: John DeSoi||Date: 2009-11-13 03:57:42|
|Subject: Re: using position in where|