When I connect to a Firebird database and try to execute a query, it throws me this error:
"Error while preparing SQL statement:")
fdb.fbcore.DatabaseError: ('Error while preparing SQL statement:\n- SQLCODE: -104\n- Dynamic SQL Error\n- SQL error code = -104\n- Token unknown - line 27, column 113\n- )', -104, 335544569)
My query looks like:
select distinct p.ID, p.DATE, p.PETITION, pac.KEY, ...,
pac.BIRTH_DATE, trunc(('today' - pac.BIRTH_DATE)/365.25) as AGE, p.NAME,...
And I've checked that the cause of the error is:
trunc(('today' - pac.BIRTH_DATE)/365.25) as AGE
if I remove it from the query, it works perfectly. Anyone knows why? Could you help me?
I've done what @ain told me:
trunc((cast(CURRENT_DATE - pac.BIRTH_DATE) as DOUBLE PRECISION)/365.25) as AGE
"Error while preparing SQL statement:")
fdb.fbcore.DatabaseError: ('Error while preparing SQL statement:\n- SQLCODE: -104\n- Dynamic SQL Error\n- SQL error code = -104\n- Database SQL dialect 1 does not support reference to DATE datatype', -104, 335544569)
But this results in the same error. Also if I try:
DATEDIFF(YEAR from CURRENT_DATE to pac.BIRTH_DATE) as AGE
"Error while preparing SQL statement:")
fdb.fbcore.DatabaseError: (
'Error while preparing SQL statement:\n-
SQLCODE: -104\n-
Dynamic SQL Error\n-
SQL error code = -104\n-
Database SQL dialect 1 does not support reference to DATE datatype',
-104, 335544569)
Finally I solved the issue by doing:
... trunc(DATEDIFF(DAY from cast(pac.BIRTH_DATE as DATE) to CURRENT_TIMESTAMP)/365.25) as AGE ...
I'll take a look to dialects too. Thank you so much for your help!
"Database SQL dialect 1 does not support reference to DATE datatype". Why do you use dialect 1 ? - ainCURRENT_TIMESTAMPinstead ofCURRENT_DATE, dialect 1 datatypeDATEis actually a timestamp, soCURRENT_DATEdoesn't work as it has an unknown datatype for dialect 1. - Mark Rotteveel