Firebird, select gives token unknown
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.