TO_DATE功能

问题描述 投票:0回答:2

我尝试按照select语句:

SELECT  coalesce(rewards_Created_Activated_Failed.membership_id, expired.membership_id) AS MembershipID
   ,coalesce(date_sub(to_date(expired.occurred_at), 'YYY-MM-DD')
                    ,to_date((max_expiredDate.expiry_date), 'YYY-MM-DD')
                    ,to_date(rewards_Created_Activated_Failed.expiry_date), 'YYY-MM-DD') AS DateMembershipExpires

FROM (
    SELECT *,
                row_number() over (PARTITION BY membership_id ORDER BY status_change_date_time asc) AS RowNum
    FROM model.movie_membership_status
            WHERE event_name in ('MembershipCreatedEvent', 'MemberShipActivatedEvent')

 ) AS rewards_Created_Activated_Failed


LEFT JOIN
(
    SELECT membership_id
          ,max(status_change_date_time) as occurred_at
    FROM model.movie_membership_status
    WHERE event_name = 'MembershipExpiredEvent'
        GROUP BY membership_id
) expired

ON expired.membership_id = rewards_Created_Activated_Failed.membership_id

但是我收到以下错误:

错误:42883:函数to_date(没有时区的时间戳)不存在

如何解决这个错误?

sql amazon-redshift
2个回答
0
投票
test=> \df to_date
                           List of functions
   Schema   |  Name   | Result data type | Argument data types |  Type  
------------+---------+------------------+---------------------+--------
 pg_catalog | to_date | date             | text, text          | normal
(1 row)

您必须提供所需的格式作为第二个参数。

the documentation


0
投票

它看起来像expired.occurred_atmax_expiredDate.expiry_daterewards_Created_Activated_Failed.expiry_date已经是约会。这意味着你不需要在它们上面调用to_date。此外,红移中没有date_sub功能。我不确定你在那里做什么,但也许看看DATEDIFF

你可能想要这样的东西(命令匹配你以前的coalesce语句):

coalesce(
  rewards_Created_Activated_Failed.expiry_date,
  expired.occurred_at,
  max_expiredDate.expiry_date
) AS DateMembershipExpires
© www.soinside.com 2019 - 2024. All rights reserved.