在 PostgreSQL 中:我使用 stringtimestamp 转换为 to_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

为什么?如何将 string 转换为 timestamp

最佳答案

一个太多的左括号。试试这个:

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!

10-06 09:44