Given the following table:
CREATE TABLE channel1m (
ts TIMESTAMP WITHOUT TIME ZONE NOT NULL,
itemId BIGINT,
value BIGINT
)
in which a row may be inserted each minute, per itemId, as follows:
ts itemId value
2012-12-03 15:29:00 100 1
2012-12-03 15:30:00 100 2
2012-12-03 15:30:00 101 0
2012-12-03 15:32:00 100 1
2012-12-03 15:32:00 101 1
I can't find a way (without creating additional tables) to write a query that fills the time gaps (for example, 15:29:00 for itemId 101, and 15:31:00 for both items) by returning NULL
in value.
The expected resultset would be:
ts itemId value
2012-12-03 15:29:00 100 1
2012-12-03 15:29:00 101 NULL
2012-12-03 15:30:00 100 2
2012-12-03 15:30:00 101 0
2012-12-03 15:31:00 100 NULL
2012-12-03 15:31:00 101 NULL
2012-12-03 15:32:00 100 1
2012-12-03 15:32:00 101 1
I've found solutions having a separate time table with the full serie of timestamps, but I would much prefer to solve this in the query alone. Is this possible?