Skip to content
Advertisement

Calculating average with biginteger time intervals using TimescaleDB

I have a schema with the following fields:

The rows contain entries with a name, a numeric value and a bigint value storing the unix timestamp in nanoseconds. Using TimescaleDB and I would like to use time_buckets_gapfill to retrieve the data. Given the timestamps are stored in bigint, this is quite cumbersome.

I would like to get aggregated data for these intervals: 5min, hour, day, week, month, quarter, year. I have managed to make it work using normal time_buckets, but now I would like to fill the gaps as well. I am using the following query now:

This returns the values correctly, but does not fill the empty spaces. If I modified my query to

I would get the first entry correctly and then empty rows every 5 minutes. How could I make it work? Thanks!

Here is a DB fiddle, but it doesn’t work as it doesn’t support TimeScaleDB. The query above returns the following:

Advertisement

Answer

You should use datatypes in your time_bucket_gapfill that matches the datatypes in your table. The following query should get you what you are looking for:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement