Page 1 of 1

trunc issue

Posted: Tue 15 Nov 2016 13:44
by albourgz
Hi,

I added a Unidac Macro to get current datetime:

Code: Select all

            m_dbOurDB->Macros->Add("CURRENTDATE","sysdate","Oracle");
            m_dbOurDB->Macros->Add("CURRENTDATE"," now() ","PostgreSQL");
Then TUniQuery

Code: Select all

SELECT A.ID, When dtpromised<={date '1900-01-10'} 
THEN 
    0 
ELSE 
    CASE WHEN dtOut={date '1900-01-01'} or dtPromised={date '1900-01-01'} THEN 
        {fn truncate({CURRENTDATE}-DTPROMISED,'')} 
    ELSE 
        {fn truncate(DTPROMISED-DTOUT,'')} 
    END 
END as DueTime, setupPrice FROM JOBS a
Works perfectly using when connected to oracle
Using postgres, it is not accepted, I get:
function trunc(interval, unknown) does not exist.

So {fn truncate} is always converted to trunc.
SQL monitor shows

Code: Select all

... THEN TRUNC( now() -DTPROMISED, '') ELSE TRUNC(DTPROMISED-DTOUT, '') END...
but it seems there is no trunc function in postgres. What can I do?

Re: trunc issue

Posted: Thu 17 Nov 2016 12:51
by azyk
In your code example the arguments set is passed to T-SQL function trunc() with such data types which this function does not support. Therefore, when calling trunc(), PostgreSQL generates the error message 'function trunc(interval unknown) does not exist' which UniDAC returns to a user application.
More details about the parameters sets of T-SQL function trunc() you can read in PostgreSQL documentation: https://www.postgresql.org/docs/current ... -math.html