Subject Re: [firebird-support] date function
Author Helen Borrie
At 11:09 AM 4/10/2004 +0700, you wrote:

>Thanks Helen... but the problem still persist...
>
> > CURRENT_DATE
> >
> > insert into aTable (aDate)
> > values (CURRENT_DATE)
>
>This works fine.
>
> > and
> > SELECT CURRENT_DATE FROM RDB$DATABASE
>
>But, this doesn't. "Field name missing" error arise.

That is not a Firebird engine error, but an error from your program. In
SQL, if you need a field name for a derived field, us the AS clause:

SELECT CURRENT_DATE FROM RDB$DATABASE AS CurrentDate

NB you can optionally omit the keyword "AS" and just provide the fieldname.


> > UPDATE aTable
> > set blah = CURRENT_DATE + 1
> >
> > DELETE from aTable
> > where date between CURRENT_DATE - 30 and CURRENT_DATE - 15
>
>This works fine too.
>
> > Operating with months isn't so simple - work out what you want and use
> > either an expression or a UDF.
>
>Alright then. I know it's not so simple, but database engine should help
>rather
>than giving it up to the users. That's what computer is all about, right?
>:) I
>hope the next minor version release (1.6?) will support DB2's date/time style
>syntax. Believe me, it'll help us a lot. :)

Get hold of some documentation and read about external functions, a.k.a.
"user-defined functions", or UDFs.


> > SELECT CURRENT_DATE, FIELD_NAME FROM ATABLE
>
>This doesn't work, same error as above.

Same solution: if your program needs a fieldname, provide one.


> > See also CURRENT_TIMESTAMP (to include time) and the predefined date
> > literals 'TODAY', 'TOMORROW', 'YESTERDAY' and 'NOW'. PDDLs have to be
> cast.
> >
> > So, these are the same:
> >
> > SELECT CURRENT_DATE + 1 FROM RDB$DATABASE
>
>This doesn't work.

It works - just doesn't work with your utility program. READ SOME SQL
DOCUMENTATION!!!


> > and
> > SELECT CAST('TOMORROW' AS DATE) FROM RDB$DATABASE
>
>This works.
>
>I don't know why some of the syntaxes above raise an error. FYI, I use
>Firebird
>1.5 on WindowsXP SP1 using dbExpress (Delphi 7). I believe the problem isn't
>with the OS or the client application since other queries work fine.

Think it over.


>It seems that predefined date literals are considered just like ordinary
>internal database variables/constants, not as special identifiers that the
>database would automagically understand what the user want from its
>position in
>the query.

It looks as though some bad experiences with utility programs are giving
you some misleading results. Consider consulting an SQL manual to solve
some of these problems.


>Oh, one more question... it seems that default udf (ib_udf and fbudf) is not
>automatically included in the database. Am I right? Or did I do something
>wrong
>in the installation? Because, I can't use ABS() without registering the udf.

That's exactly it. You must declare *in the database* any functions you
want to use with that database. There is no such thing as "installing" udf
libraries. They are EXTERNAL function libraries. To use a function, you
use DECLARE EXTERNAL FUNCTION to tell the server the entry point of the
function and the name of the library ("module_name").


>For any kind of help, I thank you all in advanced.

Get equipped with some documentation. You won't get far without at least a
language reference.

./heLen