Date

Using Postgresql's currval() function in a WHERE clause is a really bad idea. It will cause a full sequence scan on your table, no matter what. If you're unfamiliar with database lingo, "full sequence scan" means "This application is too slow! You're fired".

I was using it to get the identity of the row most recently inserted. This is a bad idea. Apparently "INSERT INTO foo VALUES () RETURNING id" is a much better idea, if you're using Postgres.

Update: If you're using a version of Postgres < 8.2, you can't use RETURNING. A work around is to do "INSERT INTO foo VALUES (); SELECT id FROM foo WHERE id = (SELECT currval('foo_id_seq'))". This prevents Postgres from noticing the currval is being compared by forcing the evaluation early, so no sequence scan.