A
A
Alexey2010-11-22 10:18:38
PostgreSQL
Alexey, 2010-11-22 10:18:38

SELECT in MySQL and PostgreSQL

Good afternoon, I recently decided to use PostgreSQL and noticed one feature, SELECT in Postres is case sensitive. If earlier in MySQL I wanted to get the testTest record and requested it in any way, it was given, but now it does not work. Is it possible to somehow build a query in Postgres so that it is not case-sensitive?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
DevMan, 2010-11-22
@elmo

SELECT *
FROM table
WHERE lower(column) = 'testtest';
or use ILIKE.

P
pwlnw, 2010-11-22
@pwlnw

It looks like it's a matter of coding. More precisely in collation.
In mysql, you used one of the case independent collation options. for example utf8_general_ci which is set by default when utf8 is selected.
If you use the lower function, then the index will probably not work.
Maybe you made a mistake when setting the encoding for the base?

P
peter23, 2010-11-22
@peter23

Postgres reduces field and table names to lowercase by default. For example, if there is a testTest field in the my_table table, then the query SELECT testTest FROM my_tablewill return an error that there is no testtest field. To get the value of this field, enclose the name in quotation marks. The request will SELECT "testTest" FROM my_tablework fine.

A
Alexey, 2010-11-22
@elmo

No, it is necessary to receive not a field and value from a field.
SELECT * FROM table WHERE = 'testtest';
or
WHERE = 'TestTest';
gave me the testTest entry, which is exactly how it was written.
The option that DevMan suggested is more or less suitable, but it’s not always convenient for me to supply a lowercase value to the input.

A
Alexey, 2010-11-22
@elmo

WHERE column ILIKE 'TestTest' is fine, Thanks DevMan.

A
Alexey, 2010-11-22
@elmo

Now logical questions about speed.
ILIKE - "They tend to be slow because there is no index support, so they must process all documents for every search."
citex - "If you declare a column as UNIQUE or PRIMARY KEY, the implicitly generated index is case-sensitive. So it's useless for case-insensitive searches, and it won't enforce uniqueness case-insensitively."
What would be more logical to use when looking for a single record that is UNIQUE and PRIMARY KEY from ~ 100 thousand.
Although my comment probably answers itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question