trunc issue

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
albourgz
Posts: 160
Joined: Wed 06 May 2009 12:17
Location: belgium

trunc issue

Post by albourgz » Tue 15 Nov 2016 13:44

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?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: trunc issue

Post by azyk » Thu 17 Nov 2016 12:51

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

Post Reply