From: | Greg Smith <greg(at)2ndquadrant(dot)com> |
---|---|
To: | fluca1978(at)infinito(dot)it |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: rationale behind quotes for camel case? |
Date: | 2011-06-28 20:37:54 |
Message-ID: | 4E0A3BA2.9070507@2ndquadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
fluca1978(at)infinito(dot)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(at)2ndQuadrant(dot)com Baltimore, MD
Comprehensive and Customized PostgreSQL Training Classes:
http://www.2ndquadrant.us/postgresql-training/
From | Date | Subject | |
---|---|---|---|
Next Message | Karsten Hilbert | 2011-06-28 20:56:35 | Re: rationale behind quotes for camel case? |
Previous Message | David Greco | 2011-06-28 18:34:30 | PLPGSQL SETOF functions |