firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Wrong report of syntax error if FORMAT clause is used

Open aafemt opened this issue 10 months ago • 2 comments

Following query reports correct error (except "source column" part):

SQL> select cast('1-1-1 1:1:1.1' as abc) from rdb$database;
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -607
-Invalid command
-Specified domain or source column ABC does not exist

Following error is incorrect:

SQL> select cast('1-1-1 1:1:1.1' as abc format 'yyyy-mm-dd hh24:mi:ss.ff4') from rdb$database;
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 1, column 36
-format

aafemt avatar Feb 28 '25 10:02 aafemt

I'm not sure that is really "wrong". In the first case, it's syntactically valid, but there is no domain with the specified name, and in the second case you have an invalid syntax, so a token unknown error is expected (or at least, only CHAR/VARCHAR/TIMESTAMP/TIME/DATE are supported here through cast_format_type).

Sure, it would be possible to adjust the parser to produce better errors, but there are a lot of other cases in the Firebird parser that result in a token unknown error if you make syntax errors.

mrotteveel avatar Feb 28 '25 12:02 mrotteveel

Consider a little mistype in datatype name. For example datetime instead of timestamp. The error in this case become very puzzling and misguiding.

aafemt avatar Feb 28 '25 12:02 aafemt