Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Case sensitivity in table names

 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i would like to know if it is possible to use case sensitive table names in an SQL query without using escaped quotes like in this query string "SELECT * FROM \"TableName\"" for example. Is there way to force the driver or query statement to recognize TabelName in mixed case without quoting? It's no big deal using quotes but it's simply annoying especially if you can't change the table names in the database itself any more.

I'm using a PostgreSQL JDBC driver 8.2 and i already found a lot of information on case sensitivity but there was no clear conclusion concerning case sensitivity in TABLE NAMES.

Thanks.

Marco
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deppends on your database. SQL Server for example can be configured to be case sensitive or not. Check the PostgreSQL docs.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, i see this problem is partly depending on the underlying database. And i've already searched the postgresql documentation for hints on how to avoid the quotes for identifier names. I just found the following statement: "SQL is case insensitive about key words and identifiers, except when identifiers are double-quoted to preserve the case..."

There are many options and parameters to set directly on the database server for incoming client connections. For example the default encoding. But i didn't find any possibility to tell the database server to use case sensitive identifier names by default.

So obviously identifier names are case insensitive by default which means at least for the JDBC driver i am using that a table named TableName will become tablename when not enclosed in backslashes and double-quotes.

And what i really wanted to know is if there is kind of a mechanism in the JDBC API or drivers to "automatically" quote identifiers in query statements and make it case sensitive this way without inserting all those annoying backslashes and double-quotes. If not then i surely will have to get used to it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic