Subject | Re: [firebird-support] Question about computed field and datediff function |
---|---|
Author | Paul Vinkenoog |
Post date | 2010-05-11T11:42:40Z |
scabaj wrote:
... DATEDIFF(YEAR FROM BORN TO CURRENT_DATE) ...
The 'DATE' shortcut cast is
a) unnecessary here (since BORN is a DATE field)
b) only allowed before a string constant
The reason that the parser doesn't immediately choke on DATE is that at
that point, it might still be possible that a string constant follows.
When it encounters BORN (a field name), the syntax becomes invalid and
an error is raised.
HTH,
Paul Vinkenoog
> I'd like to create a computed field, something like thatYes, what's wrong is the use of DATE here. Try
>
> CREATE TABLE TABLE1 (
> BORN DATE,
> AGE COMPUTED BY (DATEDIFF(YEAR FROM DATE BORN TO CURRENT_DATE))
> );
>
> or perhaps (?) better like this
>
> CREATE TABLE TABLE1 (
> BORN DATE,
> AGE COMPUTED BY ( CASE WHEN (BORN IS NULL) THEN 0 ELSE (DATEDIFF(YEAR FROM DATE BORN TO CURRENT_DATE)) END)
> );
>
> I get an error 'Invalid token... BORN'
> so the question is: is it possible in such situation to use a field name in datediff function ?
... DATEDIFF(YEAR FROM BORN TO CURRENT_DATE) ...
The 'DATE' shortcut cast is
a) unnecessary here (since BORN is a DATE field)
b) only allowed before a string constant
The reason that the parser doesn't immediately choke on DATE is that at
that point, it might still be possible that a string constant follows.
When it encounters BORN (a field name), the syntax becomes invalid and
an error is raised.
HTH,
Paul Vinkenoog