Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does PostgreSQL default everything to lower case?

I'm trying to familiarize myself with Postgres (9.2) after a fair bit of MySQL (5.1) usage, since I've been bitten by a handful of MySQL's gotchas. However, in my first five minutes with Postgres I ran into one of its gotchas, which I'm sure hits everyone:

  • By default, PostgreSQL converts everything that isn't quoted to lower case.

This isn't too big of a deal to me, since there are a couple of obvious workarounds:

  • Encapsulate everything in quotes.
  • Allow everything to be named in a lower case fashion.

But I'm wondering why. Considering how much contention I imagine this design decision causes, I'm surprised that I couldn't find any rationale on the internet. Does anybody have a thorough explanation, or preferably a link to some developer manifesto, as to why Postgres was designed this way? I'm interested.

like image 334
Hammer Bro. Avatar asked Nov 16 '12 01:11

Hammer Bro.


1 Answers

The SQL standard specifies folding unquoted identifiers to upper case. Many other RDBMS's follow the standard in this way. Firebird and Oracle both do. This means that identifier matching is, by default, case insensitive. This behavior is very important when it comes to compatibility in basic queries. In this regard MySQL's behavior is a real outlier.

However PostgreSQL deviates from the standard by folding to lower case. There are general reasons why this is considered more readable, etc. because you can use case for cuing syntax. Something like:

SELECT foo FROM bar WHERE baz = 1;

This is more natural when cases are folded to lower. The alternative folding opposite would be:

select FOO from BAR where BAZ = 1;

In general like the former behavior (folding to lower case) becasue it emphasizes the sql operations better while folding to the other case de-emphasizes the operations and emphasizes the identifiers. Given the complexity of many queries, I think the former works better.

In general the most discussion I have seen on the postgres mailing lists have been that everyone agrees the standard-mandated behavior is broken. so the above is my understanding of the issues.

like image 148
Chris Travers Avatar answered Oct 23 '22 06:10

Chris Travers