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
? – Nicarus 9 hours agodate
you are throwing away the time part.max(cat(data ->>'created_at' as timestamp))
should work: sqlfiddle.com/#!15/9eecb7db59d16c80417c72d1e1f4fbf1/9025 – a_horse_with_no_name 8 hours agomax()
a date, timestamp, etc. – Nicarus 8 hours ago