当前位置: 代码迷 >> 综合 >> PostgreSQL 错误 [42804]: ERROR: UNION types text and timestamp without time zone cannot be matched
  详细解决方案

PostgreSQL 错误 [42804]: ERROR: UNION types text and timestamp without time zone cannot be matched

热度:68   发布时间:2023-12-15 14:11:28.0

PostgreSQL 错误 [42804]: ERROR: UNION types text and timestamp without time zone cannot be matched
产生原因: 使用 UNION 联合多段 sql 语句时,每段 sql 中的相同字段类型不一致
如图,字段 zzsj 在 table_a 中类型为 timestamp ,在 table_b 中类型为字符串,此时进行 union 操作, 就会报错: 文本和时间戳无法匹配
在这里插入图片描述

解决方式: union 时将相同字段转化成相同类型, 上述报错是出现在PostgreSQL 中,故使用pg语法将字符串类型转化为 timestamp 类型
在这里插入图片描述

至此,问题解决,运行成功.

  相关解决方案