Re: rationale behind quotes for camel case? - Mailing list pgsql-general

From Greg Smith
Subject Re: rationale behind quotes for camel case?
Date
Msg-id 4E0A3BA2.9070507@2ndquadrant.com
Whole thread Raw
In response to rationale behind quotes for camel case?  (fluca1978@infinito.it)
List pgsql-general
fluca1978@infinito.it wrote:
> first of all I'm not expressing any critique against the use of quotes
> for identifier expressed using camel case. However a lot of new
> postgresql users seems to be unhappy with the use of quotes for camel
> case identifiers, so I'd like to know what is the rationale behind it.
> I mean, is a feature of the partser or is a need for it to work?
> Anyone can point me to an explaination?

The need for quoting and use of CamelCase are only vaguely related to
one another.  There are situations other than CamelCase where quotes are
needed, and using CamelCase doesn't necessarily require quotes.

If you follow the end of the documentation at
http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
you'll find this explanation of what the quoting issue is all about:

  Quoting an identifier also makes it case-sensitive, whereas unquoted
names are always folded to lower case. For example, the identifiers FOO,
foo, and "foo" are considered the same by PostgreSQL, but "Foo" and
"FOO" are different from these three and each other. (The folding of
unquoted names to lower case in PostgreSQL is incompatible with the SQL
standard, which says that unquoted names should be folded to upper case.
Thus, foo should be equivalent to "FOO" not "foo" according to the
standard. If you want to write portable applications you are advised to
always quote a particular name or never quote it.)

So saying you're unhappy with the need for quoting of mixed-case items
isn't going to get you very far, as the behavior here is all tied up
with the trivia of the SQL spec.  The specification intends that
anything other than all upper-case naming requires quoting, and
PostgreSQL turns that around to say that everything goes to lower-case
by default.  It's actually possible to leave out the quoting if you
really want to, but as advised here you have to be consistent about it.
Once you've created something with a fully quoted name, instead of
letting it "fold" the name to all lower-case, you must continue to
reference it that way in the future.  There's nothing stopping you from
just never quoting anything though.

--
Greg Smith   2ndQuadrant US    greg@2ndQuadrant.com   Baltimore, MD
Comprehensive and Customized PostgreSQL Training Classes:
http://www.2ndquadrant.us/postgresql-training/


pgsql-general by date:

Previous
From: dennis jenkins
Date:
Subject: Re: rationale behind quotes for camel case?
Next
From: Karsten Hilbert
Date:
Subject: Re: rationale behind quotes for camel case?