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 cannot infer start and finish from subquery #7605

Open
scimad opened this issue Jan 21, 2025 · 1 comment
Open

time_bucket_gapfill cannot infer start and finish from subquery #7605

scimad opened this issue Jan 21, 2025 · 1 comment

Comments

@scimad
Copy link

scimad commented Jan 21, 2025

What type of bug is this?

Unexpected error

What subsystems and features are affected?

Gapfill

What happened?

time_bucket_gapfill cannot infer start and finish from subquery.
This doesn't work:

select
	time_bucket_gapfill('5 minutes',
	created_at) bucket,
	max(value_float8)
from
	test t
where 
	t.created_at < (select max(created_at) from test t2 )
	and t.created_at > (select min(created_at) from test t2 )
group by
	bucket;

Following queries (for time_bucket and time_bucket_gapfill) works though:
TIME_BUCKET:

select
	time_bucket('5 minutes',
	created_at) bucket,
	max(value_float8)
from
	test t
where 
	t.created_at < (select max(created_at) from test t2 )
	and t.created_at > (select min(created_at) from	test t2 )
group by
	bucket;

TIME_BUCKET_GAPFILL:

select
	time_bucket_gapfill('1 hour', created_at) bucket, max(value_float8)
from
	test t
where
	t.created_at < '2025-01-18 19:08:30.628 +0000'
	and t.created_at > '2025-01-18 01:07:04.205 +0000'
group by
	bucket;

TimescaleDB version affected

2.16.1

PostgreSQL version used

15

What operating system did you use?

Mac OS X

What installation method did you use?

Homebrew

What platform did you run on?

On prem/Self-hosted

Relevant log output and stack trace

SQL Error [22023]: ERROR: missing time_bucket_gapfill argument: could not infer start from WHERE clause
  Hint: Specify start and finish as arguments or in the WHERE clause.


org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error [22023]: ERROR: missing time_bucket_gapfill argument: could not infer start from WHERE clause
  Hint: Specify start and finish as arguments or in the WHERE clause.
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:133)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:614)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$2(SQLQueryJob.java:505)
	at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:194)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:524)
	at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:976)
	at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:4155)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:123)
	at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:194)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:121)
	at org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$ResultSetDataPumpJob.run(ResultSetViewer.java:5152)
	at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:115)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.postgresql.util.PSQLException: ERROR: missing time_bucket_gapfill argument: could not infer start from WHERE clause
  Hint: Specify start and finish as arguments or in the WHERE clause.
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2725)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2412)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:371)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:502)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:419)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:341)
	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:326)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:302)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:297)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:330)
	at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:131)
	... 12 more

How can we reproduce the bug?

CREATE TABLE test (
	created_at timestamptz DEFAULT CURRENT_TIMESTAMP NULL,
	value_float8 float8 NULL,
);



select
	time_bucket_gapfill('5 minutes',
	created_at) bucket,
	max(value_float8)
from
	test t
where 
	t.created_at < (select max(created_at) from test t2 )
	and t.created_at > (select min(created_at) from test t2 )
group by
	bucket;
@scimad scimad added the bug label Jan 21, 2025
@scimad scimad changed the title [Bug]: <Title> time_bucket_gapfill cannot infer start and finish from subquery Jan 21, 2025
@mkindahl
Copy link
Contributor

@scimad Thank you for the bug report! Trivial to reproduce using your example.

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

2 participants