Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time_bucket_gapfill is not working when trying to offset the timestamp #1435

Open
cloud-rocket opened this issue Sep 10, 2019 · 11 comments
Open

Comments

@cloud-rocket
Copy link

Relevant system information:

  • OS: Kubernetes
  • PostgreSQL version (output of postgres --version): 10
  • TimescaleDB version (output of \dx in psql): 1.4.1
  • Installation method: using Docker

Describe the bug
time_bucket_gapfill is not working when trying to offset the timestamp.

To Reproduce

SELECT time_bucket_gapfill('5 minutes', time) + '2.5 minutes'
  AS five_min, last(cpu, time)
FROM metrics
GROUP BY five_min
ORDER BY five_min DESC LIMIT 10;

Expected behavior
The same behavior as with time_bucket (except the gap filling)

Actual behavior

 Could not execute the SQL command.
 Message returned: `ERROR:  no top level time_bucket_gapfill in group by clause
@sukkamehu
Copy link

sukkamehu commented Oct 11, 2019

I have the same issue. Query in below

SELECT table.id, to_char(time_bucket_gapfill('15 hours', datetime) at time zone 'utc', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') as time,
avg(value) as value, data.description from table JOIN data ON table.id = data.id where table.id in(300,301,302,303,304)
AND datetime BETWEEN '2019-05-01' AND '2019-09-30' group by time, table.id, table.description order by time DESC;

@Krummelz
Copy link

Krummelz commented Oct 11, 2019

It's not a compact workaround and ideally I would want gapfill to take an offset as well, but what I've had to resort to is running gapfill first (and depending on your requirements, using smaller buckets - say 1 hour), then wrap that in a CTE and run a query on the CTE where you do a regular time_bucket of 15 hours offset by your desired amount. Here's an example:

with gapfilled_data as ( 
  select  
    time_bucket_gapfill('1 hour', time, '2019-05-01', '2019-09-30') as hours 
    , count(*) as total 
  from history 
  where time between '2019-05-01' and '2019-09-30' 
) 
select  
  time_bucket('15 hour', hours, '6 hour') as shift 
  , sum(total) as total 
from gapfilled_data  
group by shift 
order by shift

@bboule bboule added this to the 2.0.0 milestone Oct 17, 2019
@bboule bboule self-assigned this Oct 18, 2019
@pantchox
Copy link

having the same issue when trying to add + INTERVAL '1 hour' AS hour for example.

@erimatnor erimatnor removed this from the 2.0.0 milestone Apr 16, 2020
@Nizarius
Copy link

Any updates on this?

@tiemma
Copy link

tiemma commented Apr 25, 2021

Experiencing this same issue also

@Haybu
Copy link

Haybu commented Sep 20, 2021

experiencing the same SQL Error [22023]: ERROR: no top level time_bucket_gapfill in group by clause error when using time_bucket_gapfill function. I wonder if any update. thanks.

@jflambert
Copy link

I can't seem to use time_bucket_gapfill at all (timescale 2.4.1), I always get this error

no top level time_bucket_gapfill in group by clause

@Raphyyy
Copy link

Raphyyy commented Jun 16, 2022

Same here, time_bucket_gapfill also return this error if you want to format the time column in another time format than default.
For example, formatting in Epoch :

SELECT EXTRACT
	( EPOCH FROM time_bucket_gapfill ( '5 minutes' :: INTERVAL, datetime )) AS time
FROM
	"v1" 
WHERE
	"datetime" > '2022-06-15T21:59:00' 
	AND "datetime" < '2022-06-16T12:00:00' 
GROUP BY
	"time"
ORDER BY
	"time" ASC

ERROR: no top level time_bucket_gapfill in group by clause
I don't have this issue with time_bucket

@genedavis
Copy link

@Raphyyy the documentation states that you can't embed time_bucket_gapfill in another function. Though not ideal you can get around it using a CTE, first getting the gapfill values then performing additional transformations afterwards.

@ghost
Copy link

ghost commented Dec 13, 2022

Is there a workaround for getting the time buckets to start at the "origin", like with time_bucket()? The examples in @Krummelz's workaround are good for offsetting, but I can't see how to adapt them to align my first time bucket to start at (e.g.) start_time..

@melicheradam
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests