2

When query a Derby database, I find out that for some tables I have to double quote the column name and use table name to qualify the column name, but for some other tables I don’t need to. What happens to these tables and how can I make all tables the same and can query them without the double quote and the table name qualifier? I am using NetBeans IDE’s Sql Command tool. Below are those different queries.

Set schema app;
Select * from table1 where table1.”state” = ‘CA’;
Select * from table2 where state = ‘CA’;
1
  • In fact I found some tables also need double quote and the query is like: Select “table3”.”customer” from “table3” where “table3”,”state” = ‘CA’; Commented Aug 30, 2012 at 20:03

1 Answer 1

3

Putting a tablename or column name in quotes, sometimes referred to by the jargon-y term "delimited identifiers" does two things:

  1. Allows you to use words that are otherwise reserved keywords (e.g., naming a column "WHERE" or "SELECT")
  2. Instructs the database system to process the name using case sensitive rules, rather than case-insensitive rules

So if you originally created "table3" with a CREATE TABLE statement that specified "table3" in double quotes like this, then you will forever after have to refer to it with the name in double quotes.

select * from table3

will be automatically processed by the database as if it was

select * from TABLE3

while

select * from "table3"

will successfully match the table you created as create table "table3"

See: http://db.apache.org/derby/docs/10.9/ref/crefsqlj34834.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your help. The database is created by other people. Your explanation on the double quote is very clear. But why I have to qualify every column name with the table name in my query? Even I copy the old table to a new table with the following commands: create table new_table as select * from "old_table" with no data; insert into new_table select * from "old_table";
Try using the ij "show tables" and "describe" commands to examine the schema of the database. What do "show tables" and "describe" return for table "table3"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.