Redshift中的溢出错误

时间:2018-06-05 20:01:06

标签: sql amazon-redshift

我在Amazon Redshift上运行以下非常简单的查询:

SELECT member_id,
       COUNT(DISTINCT TO_CHAR(created_at,'YYYY-MM-DD')) AS days
FROM ads.fbs_modality_staging
WHERE member_id in (select memberid from auth.members)
group by member_id

但是这给了我以下错误:

An error occurred when executing the SQL command:
SELECT member_id,
       COUNT(DISTINCT TO_CHAR(created_at,'YYYY-MM-DD')) AS days
FROM ads.fbs_modality_staging
WHERE member_id IN (SELEC...

[Amazon](500310) Invalid operation: Overflow (Integer valid range -2147483648 to 2147483647)
Details: 
 -----------------------------------------------
  error:  Overflow (Integer valid range -2147483648 to 2147483647)
  code:      1207
  context:   Value: '2952163128494839000', Character: '8'
  query:     2748804
  location:  :0
  process:   query5_95_2748804 [pid=0]
  -----------------------------------------------;

Execution time: 2.11s
1 statement failed.

我查了一下,表members没有memberid' 2952163128494839000'。我还尝试使用CONVERTCAST函数将memberid转换为integer,但我也遇到了同样的错误。

为什么我会遇到此错误,如何解决此问题?

1 个答案:

答案 0 :(得分:2)

据推测,您在成员ID比较时遇到问题。我发现你不太可能有足够的日期来溢出count(distinct)

将它们转换为字符串:

SELECT member_id,
       COUNT(DISTINCT TO_CHAR(created_at,'YYYY-MM-DD')) AS days
FROM ads.fbs_modality_staging
WHERE cast(member_id as varchar(255)) in (select cast(memberid as varchar(255)) from auth.members)
group by member_id