我在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'。我还尝试使用CONVERT
和CAST
函数将memberid
转换为integer
,但我也遇到了同样的错误。
为什么我会遇到此错误,如何解决此问题?
答案 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