timescale / timescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
https://www.timescale.com/
Other
17.33k stars 868 forks source link

Support timestamp9 within continuous aggregate time_buckets #1786

Open markns opened 4 years ago

markns commented 4 years ago

Please could timestamp9 be supported within continuous aggregate time_buckets.

We have a table that makes use of @fvannee 's timestamp9 (nanosecond precision) custom data type as the time_column. For example:

create table sensor
(
    timestamp timestamp9 not null,
    listing_id bigint not null,
    metric bigint not null,
    constraint sensor_pkey
        primary key (listing_id, timestamp)
);
SELECT create_hypertable('sensor', 'timestamp');

When I tried to create a continuous aggregate on the table as follows:

CREATE VIEW sensor_summary
WITH (timescaledb.continuous)
AS
SELECT
  time_bucket('1 hour', timestamp) as bucket,
  listing_id,
  avg(metric) as metric_avg
FROM
  sensor
GROUP BY bucket, listing_id;

The operation is not supported:

[42883] ERROR: function time_bucket(unknown, timestamp9) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 70

Adding a cast in the time_bucket function, eg. timestamp::timestamp gives a different error:

[XX000] ERROR: time_bucket function for continuous aggregate query should be called on the dimension column of the hypertable
oliora commented 2 months ago

Would be indeed useful