0
点赞
收藏
分享

微信扫一扫

mysql数据迁移opengauss时间函数str_to_date处理

一、问题描述

1、在mysql进行时间转换
select str_to_date('2050-12-31 23:59:59','%Y-%m-%d %T');
输出"2050-12-31 23:59:59"
mysql列约束:
`effect_time` datetime NOT NULL COMMENT '生效时间',
可以直接插入str_to_date('2050-12-31 23:59:59','%Y-%m-%d %T')

2、在mysql数据使用工具转换到opengauss以后
expired_time    | timestamp(6) with time zone | not null  | plain    |              | 失效时间
再进行插入就直接报错了
ERROR:  column "expired_time" is of type timestamp with time zone but expression is of type text
HINT:  You will need to rewrite or cast the expression.
从报错可以看出str_to_date('2050-12-31 23:59:59','%Y-%m-%d %T')的类型is of type text

二、解决办法

1、使用cast函数
cast(str_to_date('2050-12-31 23:59:59','%Y-%m-%d %T') as timestamp)

2、使用to_timestamp函数
to_timestamp('2050-12-31 23:59:59','yyyy-mm-dd hh24:mi:ss')

举报

相关推荐

0 条评论