Firebird – SELECT Gives Token Unknown Error

firebirdselect

I have a Firebird database with a table foo that have a field called WHEN. Is there a way to perform a query using the field name in SELECT?

This works:

SELECT * FROM foo;

This not:

SELECT WHEN FROM foo;
SQL error code = -104
Token unknown - line 1, column 18
WHEN

Any hints?

Best Answer

The token WHEN is a reserved word, and can't be used as a column name without explicitly quoting it. Either rename the column, or quote it:

select "WHEN" from foo

Be aware that quoting names makes them case sensitive. Unquoted object names in Firebird are case insensitive, but stored in uppercase.