Funny postgres query

Two days back I was facing a problem from one of the live server. The data entered by user with a minute difference, entered database with a difference of one hour. I burned my midnight oil, to figure out the reason and then to find a solution.

Finally I found the culprit. It was a funny postgres sql query. :-). Are you able to find the difference between the two queries?

insert into testtest values (to_timestamp('2009-11-11 05:32:46','yyyy-MM-dd
HH:MI:SS'))

insert into testtest values (to_timestamp('2009-11-11 05:32:46','yyyy-MM-dd HH:MI:SS')) 

Actually both the queries are same, but in first query there is a line break in the format.
Query 1
On executing the first query the data inserted was "2009-11-11 02:46:00". Difference of seconds, shifted to minutes and that of minutes to hours.

Query 2
On executing the second query, I got the expected normal result. "2009-11-11 05:32:46".

I felt this little bit weird, but so relieved after finding the problem. We were storing all the queries in XML file and did a XML formatting of the file. So every query was indented with proper line breaks.

Related Posts by Categories



Widget by Scrapur

0 comments

Post a Comment