Re: using position in where

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: using position in where
Дата
Msg-id hdr08r$6um$1@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на How to change primary key in a table  (Rikard Bosnjakovic <rikard.bosnjakovic@gmail.com>)
Список pgsql-novice
On 2009-11-13, Lynn Manhart <ManhartL@mstarmetro.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;

В списке pgsql-novice по дате отправления:

Предыдущее
От: John DeSoi
Дата:
Сообщение: Re: using position in where
Следующее
От: richard terry
Дата:
Сообщение: Adding or altering column comment