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$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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?

ITYM:
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

Browse pgsql-novice by date

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