Re: Re: Database Name Case Sensitivity

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joel Burton <jburton(at)scw(dot)org>
Cc: ADBAAMD <adba(dot)amdocs(at)bell(dot)ca>, "Brian T(dot) Allen" <brian(at)gzmarketing(dot)com>, Shaw Terwilliger <sterwill(at)sourcegear(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Re: Database Name Case Sensitivity
Date: 2001-04-05 22:16:48
Message-ID: 24856.986509008@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice

>> The "Right Thing"(TM) to do in this case would be to be case insensitive
>> by default, according to the traditional (if not standard) SQL practice,
>> and do case sensitiveness if using quotes.

The SQL spec says that double-quoted identifiers shall be treated
literally (ie, case sensitively), while unquoted identifiers shall be
folded to all upper case --- and *then* treated case sensitively. Thus,
foo FOO and "FOO" are the same name according to the spec, but "foo" and
"Foo" are two other names.

What Postgres does (and has done for a long time) is to treat
double-quoted identifiers literally while folding unquoted identifiers
to all lower case. So according to us, foo FOO and "foo" are the same
name while "FOO" and "Foo" are two other names.

Either way you get case-sensitive behavior for quoted identifiers
and non-case-sensitive behavior for unquoted ones. A query writer can
only tell that Postgres' behavior is not 100% SQL-compliant if he
writes the same name sometimes with quotes and sometimes without,
or if he looks in the system catalogs and expects to find his unquoted
table names there in a particular case.

I would not be particularly eager to see our behavior changed to get
that last little bit of spec-compliance, firstly because it would
doubtless break a lot of system-catalog-inspecting apps, and secondly
because I think the spec's choice of folding to upper case is a
brain-dead hangover from the days of teletypes. It's well-established
that lower case text is more easily readable than upper (because there's
more variation in the letter shapes). So I prefer to continue to see
table names in lower case when I look in the catalogs.

The question at hand was actually something different, because most of
what you use a database name for is outside the SQL parser proper.
It is not entirely practical to apply the SQL rules outside of SQL;
for example, if you expect
psql "FOO"
to act differently from
psql FOO
then you need to learn more about Unix shells. So our usual practice
outside of the SQL parser is just to take names literally (case
sensitively) without any foofahrah about downcasing if not quoted or
stripping quotes if present. An application could perhaps choose to
do downcasing/stripping on such names before sending them to the
postmaster, if it wanted to make database names act more like SQL names
inside its own context --- but I'd not advise doing that for names
coming from a Unix command line, because that creates a quoting mess.
(You wouldn't want to have to write psql '"FOO"' would you?)

I think there are some places that are not entirely consistent about
this; for example, IIRC pg_dump handles table names specified with -t
differently than it handles database names, which is probably a Bad
Idea. Volunteers to clean up such details are welcome...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Lohse 2001-04-05 22:36:25 php & pgsql under OSX
Previous Message ADBAAMD 2001-04-05 22:04:39 Re: Database Name Case Sensitivity

Browse pgsql-novice by date

  From Date Subject
Next Message Larry Holish 2001-04-06 03:56:49 foreign key violation
Previous Message ADBAAMD 2001-04-05 22:04:39 Re: Database Name Case Sensitivity