Skip to content

Commit

Permalink
chore: update troubleshooting info for DISTINCT. (#3461)
Browse files Browse the repository at this point in the history
* chore: update troubleshooting info for DISTINCT.
  • Loading branch information
billy-the-fish authored Oct 1, 2024
1 parent e06b496 commit a2c10e4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
41 changes: 39 additions & 2 deletions _partials/_caggs-function-support.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
This table summarizes aggregate function support in continuous aggregates:

The following table summarizes the aggregate functions supported in continuous aggregates:

|Function, clause, or feature|TimescaleDB 2.6 and earlier|TimescaleDB 2.7, 2.8, and 2.9|TimescaleDB 2.10 and later|
|-|-|-|-|
|Parallelizable aggregate functions||||
|Non-parallelizable aggregate functions||||
|[non-parallelizable SQL aggregates][postgres-parallel-agg]||||
|`ORDER BY`||||
|Ordered-set aggregates||||
|Hypothetical-set aggregates||||
|`DISTINCT` in aggregate functions||||
|`FILTER` in aggregate functions||||
|`FROM` clause supports `JOINS`||||


DISTINCT works in aggregate functions not in the query definition. For example, for the table:

```sql
CREATE TABLE public.candle(
symbol_id uuid NOT NULL,
symbol text NOT NULL,
"time" timestamp with time zone NOT NULL,
open double precision NOT NULL,
high double precision NOT NULL,
low double precision NOT NULL,
close double precision NOT NULL,
volume double precision NOT NULL
);

```
- The following works:
```sql
CREATE MATERIALIZED VIEW candles_start_end
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 hour', "time"), COUNT(DISTINCT symbol), first(time, time) as first_candle, last(time, time) as last_candle
FROM candle
GROUP BY 1;
```
- This does not:
```sql
CREATE MATERIALIZED VIEW candles_start_end
WITH (timescaledb.continuous) AS
SELECT DISTINCT ON (symbol)
symbol,symbol_id, first(time, time) as first_candle, last(time, time) as last_candle
FROM candle
GROUP BY symbol_id;
```

[postgres-parallel-agg]: https://www.postgresql.org/docs/current/parallel-plans.html#PARALLEL-AGGREGATION
26 changes: 7 additions & 19 deletions _troubleshooting/caggs-queries-fail.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ title: Queries fail when defining continuous aggregates but work on regular tabl
section: troubleshooting
products: [cloud, mst, self_hosted]
topics: [continuous aggregates]
errors:
- language: sql
message: |-
ERROR: invalid continuous aggregate view
SQL state: 0A000
apis:
- [continuous aggregates, CREATE MATERIALIZED VIEW (Continuous Aggregate)]
keywords: [continuous aggregates]
Expand All @@ -16,22 +11,15 @@ tags: [continuous aggregates, query]

import CaggsFunctionSupport from 'versionContent/_partials/_caggs-function-support.mdx';

<!---
* Use this format for writing troubleshooting sections:
- Cause: What causes the problem?
- Consequence: What does the user see when they hit this problem?
- Fix/Workaround: What can the user do to fix or work around the problem? Provide a "Resolving" Procedure if required.
- Result: When the user applies the fix, what is the result when the same action is applied?
* Copy this comment at the top of every troubleshooting page
-->

Continuous aggregates don't work on all queries. If you are using a function
that continuous aggregates do not support, you see the error above.
Continuous aggregates do not work on all queries. For example, TimescaleDB does not support window functions on
continuous aggregates. If you use an unsupported function, you see the following error:

TimescaleDB doesn't support window functions on continuous aggregates.
In versions earlier than 2.7, it doesn't support any
[non-parallelizable SQL aggregates][postgres-parallel-agg].
```sql
ERROR: invalid continuous aggregate view
SQL state: 0A000
```

<CaggsFunctionSupport />


[postgres-parallel-agg]: https://www.postgresql.org/docs/current/parallel-plans.html#PARALLEL-AGGREGATION

0 comments on commit a2c10e4

Please sign in to comment.