Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a string representing a timestamp to an actual timestamp in PostgreSQL?

In PostgreSQL: I convert string to timestamp with to_timestamp():

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

But I get this error:

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

Why? How to convert a string to timestamp?

like image 651
mum Avatar asked Nov 28 '12 12:11

mum


1 Answers

One too many opening brackets. Try this:

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

You had two opening brackets at to_timestamp:

where to_timestamp((COA.. -- <-- the second one  is not needed!
like image 142
ppeterka Avatar answered Oct 29 '22 12:10

ppeterka