我尝试按照选择陈述:
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(没有时区的时间戳)不存在
如何修复该错误?
答案 0 :(得分: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)
您必须提供所需的格式作为第二个参数。
答案 1 :(得分:0)
看起来expired.occurred_at
,max_expiredDate.expiry_date
和rewards_Created_Activated_Failed.expiry_date
已经是日期。这意味着您无需在其上调用to_date
。此外,redshift中没有date_sub
函数。我不确定你在那里做什么,但也许看看DATEDIFF?
你可能想要这样的东西(命令匹配你以前的合并声明):
coalesce(
rewards_Created_Activated_Failed.expiry_date,
expired.occurred_at,
max_expiredDate.expiry_date
) AS DateMembershipExpires