Categories

Archives

Did You Know?

Although it is time consuming, I enjoy the art of application reverse-engineering. An early version of Roger Wilco fell victim to my curiosity.

Recent Comments

Tags

asp audio browser bug business coalesce code crash Database db debian extension framework imap internet legions linux metaverse mysql obscurity patch PHP postgresql properties release scp Second Life second life security session social media sound sql ssh subversion tables tortoisesvn tribes ubuntu virtual world web windows zend zend framework zf

Indexes in PostgreSQL

One thing that most people don't have to worry about in MySQL is case-sensitivity. Unless you're trying to authenticate a user against a database password and don't use MD5 (like you should!), in which case the password is not case sensitive by default.

In PostgreSQL everything is case sensitive. That means that if you have a user "Bob", and you run a query such as:

SELECT * FROM users WHERE username = 'bob';

you won't get a match. You can get around that by using:

SELECT * FROM users WHERE LOWER(username) = LOWER('bob');

However, now PostgreSQL will ignore your regular index on the username column. Fortunately, PostgreSQL will let you create indexes based on expressions. In this case you'd want to use the following index:

CREATE UNIQUE INDEX myindex ON users((LOWER(username));

Cheers!

Write a comment