Search code examples
javajunitdb2hsqldb

HSQL column name contains #


I'm working on using JUnit to test an application. I've decided to use HSQL to create an in memory database at run time. This works fine when I am mocking an Oracle database. However, when I try to mock our existing DB2 database, I run into an issue. One of the columns we use has the # symbol in the column name (i.e. "Person#"). HSQL can not interpret this character and will throw a hard error when trying to load the schema.

I've tried to put HSQL in DB2 mode and still no luck. Is it possible to use a # symbol in HSQL or any other in memory database? Unfortunately changing the column name would be too much work for simply test coverage.


Solution

  • you need to enclose the column name in double quotes:

    CREATE TABLE foo 
    (
      "PERSON#"   VARCHAR(10)
    )
    

    unfortunately you will then need to always use double quotes when accessing that column