Skip to content
Advertisement

is “SELECT fieldname, fieldName FROM MY_TABLE;” ever valid for any SQL database?

Do any SQL databases have case-sensitive naming for field names?

What I mean is, in Java you can have two variables …

String fieldname = "a";
String fieldName = "b";

Are there any SQL databases support that so …

SELECT fieldname, fieldName FROM MY_TABLE;

… would return two different columns?

I’m asking because I’m building a database utility that has to work for MySQL, H2, PostgreSQL, Oracle, and SQL Server, so I need to know how they all work for a bit of code I’m writing.

Advertisement

Answer

By the SQL standard, SQL identifiers are case-insensitive. So, without escape characters, these refer to the same column:

select fieldname, fieldName

However, you can escape the names and they become distinguishable. The standard SQL escape character is ":

select "fieldname", "fieldName"

But some databases don’t support this and have their own.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement