Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 539 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you write a case insensitive query for both MySQL and Postgres?

#11
There are several answers, none of which are very satisfactory.

* **LOWER(bar) = LOWER(?)** will *work* on MySQL and Postgres, but is likely to *perform terribly on MySQL*: MySQL won't use its indexes because of the LOWER function. On Postgres you can add a functional index (on **LOWER(bar)**) but MySQL doesn't support this.
* MySQL will (unless you have set a case-sensitive [collation][1]) do case-insensitive matching automatically, and use its indexes. (**bar = ?**).
* From your code outside the database, maintain **bar** and **bar_lower** fields, where bar_lower contains the result of **lower(bar)**. (This may be possible using database triggers, also). (See a discussion of this solution on [Drupal][2]). This is clumsy but does at least run the same way on pretty much every database.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#12
REGEXP is case insensitive (unless used with BINARY), and can be used, like so...

SELECT id FROM person WHERE name REGEXP 'john';

...to match 'John', 'JOHN', 'john', etc.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through