使用DataGrip执行时,给定的查询完全正常,但在lib / pq提交时返回以下错误:
pq: a negative number raised to a non-integer power yields a complex result
错误发生在postgres中,因为它显示在日志中
SELECT upvotes / (EXTRACT(EPOCH FROM current_timestamp-created_at)/3600)^1.8 as score, title,
FROM ideas
ORDER BY score desc
简化架构
create table ideas
(
title text not null,
created_at timestamp not null,
upvotes integer default 0 not null
)
我正在运行postgres v9.2
我很高兴看到有什么可以调查的暗示,因为我没有想法。
答案 0 :(得分:1)
所以,你以后会以某种方式获得一些时间戳。您可以保护查询以确保使用GREATEST
没有负面结果SELECT upvotes / (GREATEST(EXTRACT(EPOCH FROM current_timestamp-created_at)/3600),0)^1.8 as score, title,
FROM ideas
ORDER BY score desc
或者,您可以使用WHERE子句排除错误数据。
SELECT upvotes / (EXTRACT(EPOCH FROM current_timestamp-created_at)/3600)^1.8 as score, title,
FROM ideas
WHERE current_timestampn >= created_at
ORDER BY score desc