I am trying to write a query that needs using the function MAX(). The data is stored in a jsonb column like:
{"created_at": "2012-08-03T02:32:44", "company": "apple"}.
I would like to run the MAX() function on the 'created_at' key.
SELECT MAX(data -> 'created_at) FROM ... does not work.
SELECT MAX(cast(data -> 'created_at) as DATE) FROM ... does not work as well.
->just returnsjson. Did you try->>which returnstext?dateyou are throwing away the time part.max(cat(data ->>'created_at' as timestamp))should work: sqlfiddle.com/#!15/9eecb7db59d16c80417c72d1e1f4fbf1/9025max()a date, timestamp, etc.