Re: PostgreDB stores table name is lower case

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: 王波 <853372309(at)qq(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: PostgreDB stores table name is lower case
Date: 2016-11-25 23:19:18
Message-ID: aad4c17d-09a8-2525-23fe-c745d0c6ba27@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/23/2016 11:52 PM, 王波 wrote:
> Hello :
>
> I'am a Postgre fan.
> Now, I have a problem, the table name is stored in lower case ,
> but i want to change it into upper case. Can i have a simple method?
> Such as modify a parameter.

https://www.postgresql.org/docs/9.5/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

"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.)"

There is no parameter to set. If you want upper case names then you need to quote them:

test[5432]=# create table FOLD_LOWERCASE ();
CREATE TABLE
test[5432]=# create table "QUOTE_UPPERCASE" ();
CREATE TABLE

test[5432]=# \d fold_lowercase
Table "public.fold_lowercase"
Column | Type | Modifiers
--------+------+-----------

test[5432]=# \d FOLD_LOWERCASE
Table "public.fold_lowercase"
Column | Type | Modifiers
--------+------+-----------

test[5432]=# \d QUOTE_UPPERCASE
Did not find any relation named "QUOTE_UPPERCASE".

test[5432]=# \d quote_uppercase
Did not find any relation named "quote_uppercase".

test[5432]=# \d "QUOTE_UPPERCASE"
Table "public.QUOTE_UPPERCASE"
Column | Type | Modifiers
--------+------+-----------

The above also shows what happens when you quote, you are committed
to that case.

If you still want to do this then:

test[5432]=# ALTER table fold_lowercase rename to "MAKE_UPPERCASE";
ALTER TABLE

test[5432]=# \d "MAKE_UPPERCASE"
Table "public.MAKE_UPPERCASE"
Column | Type | Modifiers
--------+------+-----------

>
> Thank you!
>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2016-11-25 23:44:10 Re: PostgreDB stores table name is lower case
Previous Message Jeff Janes 2016-11-25 23:08:53 Re: Query regarding deadlock