I have to work with a table that looks like this:
The actual table is obviously much larger, but for sake of discussion, is there any way to elegantly query the difference between when { a: null }
turned into { a: "something"? }
My instinct is to try something (probably pseudocode) like this:
select (select update_time as finish_time from fun_table where json_data -> 'a' != 'null' as tableA) - (select update_time as start_time from fun_table where json_data -> 'a' = 'null as tableB) from tableA, tableB
But there are a lot of different JSON objects in the actual json_data…"b", "c", etc. So again, is there a better / cleaner way to find the difference between the timestamps when "a" turned from "null" to "something"?
Best Answer
JSONB supports equality checks. So, if you're using it, you need only
Create an
AFTER
trigger onEither,
id
, andnew.update_time
into a new table, orupdate_time
setting it the current time, and query later forupdate_time
>last_time_ran
.