Thread: CREATE DATABASE

CREATE DATABASE

From
jose
Date:
Hi,

PostgreSQL is not consistent in the way it uses upper/lower case to
create databases and access it.
Why psql -c 'CREATE DATABASE name_db'  uses lower(name_db) an less the
name is enclosed by "" but psql name_db ?
Take a look ....

psql template1 -c "create database MYDB"
psql  MYDB

psql: FATAL 1: Database "MYDB" does not exist in the system catalog.

Jo


Re: CREATE DATABASE

From
Tom Lane
Date:
jose <jose@sferacarta.com> writes:
> PostgreSQL is not consistent in the way it uses upper/lower case to
> create databases and access it.

Folding case in unquoted names in SQL commands is required by the spec.
On the other hand, we decided some time ago that names appearing in
command-line arguments should be taken literally.  Before that we tried
to make the command tools work like SQL, but that didn't work well
because the shell is going to process the arguments before we get them.

For example, suppose in SQL you do
    create database "MyDb";

Now when you want to connect to it, you try
    psql "MyDb"
Unfortunately the shell is going to strip those double quotes, so what
psql gets is going to look like just MyDb.  If it thinks to itself
"unquoted, so fold to lower case", then you lose.  People ended up
having to do things like
    psql '"MyDb"'
to get to their mixed-case databases.

In short, it's inconsistent because it works better this way.

            regards, tom lane

Re: CREATE DATABASE

From
Peter Eisentraut
Date:
jose writes:

> PostgreSQL is not consistent in the way it uses upper/lower case to
> create databases and access it.
> Why psql -c 'CREATE DATABASE name_db'  uses lower(name_db) an less the
> name is enclosed by "" but psql name_db ?

These are two different language bindings for the same functionality.
You could also claim that Unix is not consistent because C programs and
shell scripts provide different ways to do the same thing.  You would be
right, but it's nevertheless quite intended that way.

--
Peter Eisentraut   peter_e@gmx.net