I have recently tried to create some tables in PostgreSQL all in uppercase names. However in order to query them I need to put the table name inside the "TABLE_NAME". Is there any way to avoid this and tell the postgres to work with uppercase name as normal ?
UPDATE
this query create a table with lowercase table_name
create table TABLE_NAME
(
id integer,
name varchar(255)
)
However, this query creates a table with uppercase name "TABLE_NAME"
create table "TABLE_NAME"
(
id integer,
name varchar(255)
)
the problem is the quotations are part of the name now!! in my case I do not create the tables manually, another Application creates the table and the names are in capital letters. this cause problems when I want to use CQL filters via Geoserver.
The question implies that double quotes, when used to force PostgreSQL to recognize casing for an identifier name, actually become part of the identifier name. That's not correct. What does happen is that if you use double quotes to force casing, then you must always use double quotes to reference that identifier.
Background:
In PostgreSQL, names of identifiers are always folded to lowercase unless you surround the identifier name with double quotes. This can lead to confusion.
Consider what happens if you run these two statements in sequence:
That creates a table named
my_table
.Now, try to run this:
PostgreSQL ignores the uppercasing (because the table name is not surrounded by quotes) and tries to make another table called
my_table
. When that happens, it throws an error:To make a table with uppercase letters, you'd have to run:
Now you have two tables in your database:
The only way to ever access
My_Table
is to then surround the identifier name with double quotes, as in:If you leave the identifier unquoted, then PostgreSQL would fold it to lowercase and query
my_table
.In simple words, Postgres treats the data in (double-quotes)
""
as case-sensitive. And remaining as lowercase.Example: we can create 2-columns with names DETAILS and details and while querying:
return
DETAILS
column data andreturns details column data.
put table name into double quotes if you want postgres to preserve case for relation names.
from docs (emphasis mine)
example with quoting:
example without quoting:
So if you created table with quotes, you should not skip quotes querying it. But if you skipped quotes creating object, the name was folded to lowercase and so will be with uppercase name in query - this way you "won't notice" it.