类型间隔的无效输入语法:"missing"

invalid input syntax for type interval: "missing"

我正在使用 PostgreSQL 8.4.4。我的问题是,我正在根据两个 bigint 值计算以天-小时-分钟为单位的时差。我将这些值转换为时间戳,然后计算差异。我得到 table 中存在的值的差异。但是对于 return NULL 或 table 中不存在的那些,我希望结果为 'Missing'。当我在查询中添加它时,出现上述错误。以下是我正在使用的查询:

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

您可以使用 coalesce() and nullif() 函数的组合来实现结果,而不是像下面那样使用 CASE-WHEN

SELECT coalesce(nullif(age(to_timestamp(incepted_date), to_timestamp(invoice_pay_date))::TEXT, ''), 'Missing')
FROM transactions_transactions
WHERE id = 4275