【发布时间】:2017-06-11 09:04:49
【问题描述】:
在 postgres 中,当我尝试合并两个表时出现错误,其中一个表的列 (Amount) 包含 double precision 数据类型,而另一个表没有匹配的列,我希望该表中的记录在 Amount 字段中只有 NULL。
错误:
“联合类型文本和双精度不能匹配postgres”
伪代码:
SELECT * FROM (
SELECT
t1.Amount AS 'amount',
NULL::DATE AS 'date'
FROM Table1 AS t1
UNION ALL
SELECT
/* next line is the issue */
NULL AS 'amount',
t2.Date AS 'date'
FROM Table2 AS t2
) AS FOO
我相当肯定这个解决方案是一个简单的铸造问题,但无法通过搜索找到任何东西。我如何在 postgres 中做相当于 NULL::DOUBLE 的操作?
EDIT::POSTERITY
@klin 和@a_horse_with_no_name 的评论中接受的答案指向“历史”postgres 演员表表达式::,其中syntax is equivalent:
CAST ( expression AS type )
expression::type
还有,这里是postgres data types 的列表。
【问题讨论】:
标签: postgresql