Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgreSQL sorting with timestamps

I have the following SQL statement:

SELECT * FROM schema."table"
  WHERE "TimeStamp"::timestamp >= '2016-03-09 03:00:05'
  ORDER BY "TimeStamp"::date asc
  LIMIT 15

What do I expect it to do? Giving out 15 rows of the table, where the timestamp is the same and bigger than that date, in ascending order. But postgres sends the rows in the wrong order. The first item is on the last position. SQL Editor with result So has anyone an idea why the result is this strange?

like image 667
Garamaru Avatar asked Dec 15 '22 04:12

Garamaru


1 Answers

Use simply ORDER BY "TimeStamp" (without casting to date).

like image 199
klin Avatar answered Dec 28 '22 23:12

klin