Re: Lower case

Started by Tino Wildenhainabout 21 years ago4 messagesgeneral
Jump to latest
#1Tino Wildenhain
tino@wildenhain.de

Hi,

On Wed, 2005-01-26 at 12:01 +0000, Vladimir S. Petukhov wrote:

Hi!

Sorry for my English..

I want to do case-insensitivity search, like this
... WHERE lower (column_name) LIKE lower (%value%);
This work fine for English..
But i need search for Russian words, lower() operator does not work with
Russian (non-English) chars, but ORDER works fine...
???????????????
What's wrong?

lower(), upper() and case insensitive search highly depend on
the correct locale. The locale is currently set on initdb
time, that is, when your whole cluster gets created.

If you dont want to recreate your cluster and your db,
you probably need to write a function to lower()
according to your datas locale.

Regards
Tino
--
Tino Wildenhain <tino@wildenhain.de>

#2Dawid Kuroczko
qnex42@gmail.com
In reply to: Tino Wildenhain (#1)

On Wed, 26 Jan 2005 12:01:49 +0000, Vladimir S. Petukhov
<vladimir@sycore.org> wrote:

I want to do case-insensitivity search, like this
... WHERE lower (column_name) LIKE lower (%value%);
This work fine for English..
But i need search for Russian words, lower() operator does not work with
Russian (non-English) chars, but ORDER works fine...
???????????????
What's wrong?

Welllllll... Have you made an initdb with apropriate locale setting?
Try:
pg_controldata /var/lib/postgresql/data
(or wherever your db is)
You should see lines like:
LC_COLLATE: C
LC_CTYPE: C

If you are using Unicode these should be ru_RU.UTF-8, if not then
ru_RU.KOI8-R or something. If you see 'C', or 'en_EN' or similar
then you won't have Russian lower/upper support (and ORDER BY
was just a "luck" :)).

What you can do:
pg_dump the database, initdb --locale=ru_RU; pg_restore the database.

Ohhh, and since you're at it, there is one thing which makes me
wonder and if you don't mind, please try it. :) This will require
plperlu language, so 'createlang plperlu' and that you use
unicode encoding in your database.

Try if this function:
CREATE OR REPLACE FUNCTION lc(text) RETURNS text AS $$
utf8::decode($_[0]);
return lc($_[0]);
$$ LANGUAGE plperlu STABLE;

Used as select lc(your_text_column) from your_table;
works for Russian alphabet. :) I'm just cuuurious! :)

Regards,
Dawid

#3Michal Hlavac
hlavki@medium13.sk
In reply to: Tino Wildenhain (#1)

Tino Wildenhain wrote:

Hi,

On Wed, 2005-01-26 at 12:01 +0000, Vladimir S. Petukhov wrote:

Hi!

Sorry for my English..

I want to do case-insensitivity search, like this
... WHERE lower (column_name) LIKE lower (%value%);
This work fine for English..
But i need search for Russian words, lower() operator does not work with
Russian (non-English) chars, but ORDER works fine...
???????????????
What's wrong?

what about ILIKE operator?

miso

#4Vladimir S. Petukhov
vladimir@sycore.org
In reply to: Dawid Kuroczko (#2)

pg_controldata /var/pgsql/data
...
LC_COLLATE: ru_RU
LC_CTYPE: ru_RU

bash-2.05b# psql -l
List of databases
Name | Owner | Encoding
-----------+----------+----------
testdb | postgres | UNICODE

And LIKE, ILIKE, ~ do not recognize upper/lower case..
SELECT ... ORDER BY do something like that (in English Alphabet):
a
AAAA
aaaaa
Tast12
tes
test
Test12
test12

?:(

On Wednesday 26 January 2005 10:15, Dawid Kuroczko wrote:

On Wed, 26 Jan 2005 12:01:49 +0000, Vladimir S. Petukhov

<vladimir@sycore.org> wrote:

I want to do case-insensitivity search, like this
... WHERE lower (column_name) LIKE lower (%value%);
This work fine for English..
But i need search for Russian words, lower() operator does not work with
Russian (non-English) chars, but ORDER works fine...
???????????????
What's wrong?

Welllllll... Have you made an initdb with apropriate locale setting?
Try:
pg_controldata /var/lib/postgresql/data
(or wherever your db is)
You should see lines like:
LC_COLLATE: C
LC_CTYPE: C

If you are using Unicode these should be ru_RU.UTF-8, if not then
ru_RU.KOI8-R or something. If you see 'C', or 'en_EN' or similar
then you won't have Russian lower/upper support (and ORDER BY
was just a "luck" :)).

What you can do:
pg_dump the database, initdb --locale=ru_RU; pg_restore the database.

Ohhh, and since you're at it, there is one thing which makes me
wonder and if you don't mind, please try it. :) This will require
plperlu language, so 'createlang plperlu' and that you use
unicode encoding in your database.

Try if this function:
CREATE OR REPLACE FUNCTION lc(text) RETURNS text AS $$
utf8::decode($_[0]);
return lc($_[0]);
$$ LANGUAGE plperlu STABLE;

Used as select lc(your_text_column) from your_table;
works for Russian alphabet. :) I'm just cuuurious! :)

Regards,
Dawid

--
Скунсу и не надо быть красивым. Его и так все уважают.

Now playing:
AutoGenerated by fortune & xmms...