Search code examples
sqlderby

How to use keywords as column names in Derby


Can I use reserved keywords as column names in Derby? I'm trying to migrate database schema into Derby for testing purposes. For that reason I don't really want to change the schema structure (column names etc).

So the question is, how can I create table with column name "open" in Derby? As for example table:

create table test ( open integer );

Tried to quote the column name, but so far no success...

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "open" at line 1, column 21.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)

Solution

  • The standard way of quoting reserved words (and Derby follows the standard as nearly all DBMS do in that regard) is to use double quotes.

    create table test ( "OPEN" integer );
    

    But beware that once you do that column (or table) names become case-sensitive. "OPEN" is a different column than "open" or "Open".

    I would strongly suggest you do not use names that require you to quote them.