I have the following table in PostgreSQL 9.2 that contains timestamps:
gid [PK] (bigserial), timestamp_mes (timestamp without time zone), time_diff (interval)
1, 2012-01-23 11:03:40, empty
2, 2012-01-23 11:03:42, empty
3, 2012-01-23 11:03:44, empty
I added a column interval (time_diff) and would like to populate it with the time difference values ​​obtained from this query:
SELECT timestamp_mes - lag(timestamp_mes, 1) over (order by timestamp_mes) as diff from gc_entretien.trace order by timestamp_mes
I tried the following query to update the time_diff column without success:
UPDATE gc_entretien.trace set time_diff = (SELECT trace.timestamp_mes - lag(trace.timestamp_mes, 1) over (order by trace.timestamp_mes) from gc_entretien.trace order by timestamp_mes);
This will result in an error:
ERROR: more than one row returned by the subquery used as expression
How can I switch to updating the time_diff column with the values ​​obtained as a result of requesting the time difference?
jatobat
source share