将Oracle Query转换为PostgreSQL

时间:2017-09-19 12:16:41

标签: sql database oracle postgresql pentaho-data-integration

我发布了我的查询的一部分,该查询位于Oracle中,如下所示:

cast(from_tz(cast((Select max(d.startdate) from Public.result_slalom d 
               where d.eventid = a.eventid 
               and d.modifydate = (Select max(e.modifydate) from result_slalom e 
                where e.eventid = d.eventid)) as timestamp), 'Asia/Calcutta') at Time Zone 'Europe/Berlin' as date) as OpenLastTime,

我想在PostgreSQL上运行此查询。所以我写了一个类似于PostgreSQL的查询:

(Select Cast(to_timestamp(max(d.startdate)) 
                      from Public.result_slalom d 
               where d.eventid = a.eventid 
               and d.modifydate = (Select max(e.modifydate) from Public.result_slalom e
                where e.eventid = d.eventid) as timestamp, 'Asia/Calcutta') at Time Zone 'Europe/Berlin' as date) as OpenLastTime,

我在这里和那里得到一些错误,我认为这些错误与一些支架问题有关。或者由于关键字'时间戳'在e.modifydate的第二个select子句中。

非常感谢任何帮助。提前致谢。 :)

1 个答案:

答案 0 :(得分:0)

将来,请尝试添加我们实际可以运行的完全可重现的示例。我做了an example fiddle that shows how you could do this

from_tz不是Postgres功能。此外,Postgres中的date类型没有时间或时区组件 - 它只是年 - 月 - 日。您的startdatemodifydate列必须为timestamp类型。

这是我的转换:

select ((Select max(d.startdate) from result_slalom d 
           where d.eventid = a.eventid and 
           d.modifydate = (Select max(e.modifydate) from result_slalom e 
             where e.eventid = d.eventid)) at time zone 'Asia/Calcutta') 
        at Time Zone 'Europe/Berlin' as OpenLastTime
from a;