【发布时间】:2015-12-20 07:33:27
【问题描述】:
我正在使用 PostgreSQL 8.4.4。我的问题是,我正在从两个 bigint 值计算以天-小时-分钟为单位的时间差。我将这些值转换为时间戳,然后计算差异。我得到了表中存在的值的差异。但对于那些返回NULL 或表中不存在的人,我希望结果为“缺失”。当我在查询中添加它时,我得到了上述错误。以下是我正在使用的查询:
select
case when exists (SELECT age(to_timestamp(incepted_date), to_timestamp(invoice_pay_date))
from transactions_transactions where id = 4275)
then (SELECT age(to_timestamp(incepted_date), to_timestamp(invoice_pay_date))
from transactions_transactions where id = 4275)
else 'missing'
end
【问题讨论】:
-
试试这个
select coalesce(nullif(age(to_timestamp(incepted_date), to_timestamp(invoice_pay_date))::text,''),'Missing') FROM transactions_transactions WHERE id = 4275或者这个-hastebin.com/iyaxavilef.sql -
非常感谢@winged panther 的快速响应,解决方案按预期工作。
标签: postgresql select timestamp bigint