> Hi all, > > I have a table with value and timestamp columns. What I like to do (but am unable to find a solution) is to select the last(value) timestamp combination in every X minute interval where timestamp is between N and M. Is this possible with pgsql? >
maybe somethink like
select *, row_number() over (partition by to_char(timestamp, 'yyyy-mm-dd hh24:mm') order by ... desc) ...
and then pick all with row_number = 1
*untested*
Unproven but whenever you have a query of this form (row_number = 1) you should consider/test whether using DISTINCT ON with an appropriate ORDER BY clause gives you the answer faster and/or more clearly.