【问题标题】:Conversion of Oracle Query to PostgreSQLOracle 查询到 PostgreSQL 的转换
【发布时间】:2018-02-28 05:27:58
【问题描述】:

我在 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 的第二个选择子句中的关键字“时间戳”。

任何帮助将不胜感激。提前致谢。 :)

【问题讨论】:

  • 这在任一数据库中都不起作用,因为未定义 a。我建议您简化您的实际查询,然后改写问题或提出另一个问题。
  • 您得到的“这里和那里的一些错误”到底是什么?对不起,我的水晶球坏了。

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


【解决方案1】:

以后,请尝试包含一个我们可以实际运行的完全可重现的示例。我发了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;

【讨论】:

    猜你喜欢
    • 2023-02-01
    • 2013-11-18
    • 2015-04-14
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多