如何将联合中的空列转换为最新日期?

Rus*_*ord 5 postgresql

[SQL 初学者]

我有如下所示的 sql 查询:

select * from 
(select '' as dates from table1

union 

select dates from table2)
Run Code Online (Sandbox Code Playgroud)

当我运行这个查询时,我收到错误UNION types text and timestamp without time zone cannot be matched

我尝试将dates表 2 中的列转换为 varchar,但这不是我想要的。如何将 table1 中的空字段转换为日期时间?

我试过这个:

select * from 
(select cast(('' as dates) as date) as dates from table1

union 

select dates from table2)
Run Code Online (Sandbox Code Playgroud)

但这也不起作用。

Isl*_*gre 6

赋予它null价值。这可以转换为任何数据类型。

SELECT * 
FROM (
    SELECT null::timestamp AS dates FROM table1
    UNION
    SELECT dates FROM table2
) t
Run Code Online (Sandbox Code Playgroud)

SELECT注意:您还可以使用 . 代替“空”日期VALUES