Category Archives: SQL

Perfect hash function for weekday names

This is probably only of limited usefulness in practice, but it came as a spinoff from a discussion on #postgresql. The basic problem is, given a string which you already know is an English weekday name, return the day number … Continue reading

Posted in PlanetPG, Postgres, SQL | Comments Off on Perfect hash function for weekday names

Performance issues with ORed conditions

An issue that comes up from time to time on the IRC channel is performance optimization of queries that contain ORed conditions. Here is a summary of the common problems and some solutions.

Posted in PlanetPG, Postgres, SQL | 2 Comments

Range aggregation with window functions

This article is also available on the PG wiki here This problem is one I’ve been asked about a couple of times on IRC; the solution involves some tricks with window functions that have a fairly wide range of applications. … Continue reading

Posted in PlanetPG, Postgres, SQL | Comments Off on Range aggregation with window functions

On Normalization

People have funny ideas about database normalization. What normalization is not: creating an (id,value) table for every single piece of data is not normalization using surrogate keys for everything is not normalization a way to improve performance (though it sometimes … Continue reading

Posted in Peeves, PlanetPG, SQL | Comments Off on On Normalization