gpt4 book ai didi

postgresql - 将表示时间戳的字符串转换为 PostgreSQL 中的实际时间戳?

转载 作者:行者123 更新时间:2023-11-29 11:23:16 28 4
gpt4 key购买 nike

在 PostgreSQL 中:我使用 to_timestamp()string 转换为 timestamp:

select * from ms_secondaryhealthcarearea
where to_timestamp((COALESCE(update_datetime, '19900101010101'),'YYYYMMDDHH24MISS')
> to_timestamp('20121128191843','YYYYMMDDHH24MISS')

但是我得到这个错误:

ERROR:  syntax error at end of input
LINE 1: ...H24MISS') >to_timestamp('20121128191843','YYYYMMDDHH24MISS')
^
********** Error **********

ERROR: syntax error at end of input
SQL state: 42601
Character: 176

为什么?如何将字符串转换为时间戳

最佳答案

左括号太多。试试这个:

select * 
from ms_secondaryhealthcarearea
where to_timestamp(COALESCE(update_datetime, '19900101010101'),'YYYYMMDDHH24MISS') >to_timestamp('20121128191843','YYYYMMDDHH24MISS')

您在 to_timestamp 处有两个左括号:

where to_timestamp((COA.. -- <-- the second one  is not needed!

关于postgresql - 将表示时间戳的字符串转换为 PostgreSQL 中的实际时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13605630/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com