https://github.com/binakot/timescaledb-error-distinct-on-single-object-array-and-second-order-by
Bug report to TimescaleDB about broken 'distinct on'
https://github.com/binakot/timescaledb-error-distinct-on-single-object-array-and-second-order-by
bug error planner postgres postgresql sql timescaledb
Last synced: 3 months ago
JSON representation
Bug report to TimescaleDB about broken 'distinct on'
- Host: GitHub
- URL: https://github.com/binakot/timescaledb-error-distinct-on-single-object-array-and-second-order-by
- Owner: binakot
- License: mit
- Created: 2021-10-01T07:26:52.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-01T07:32:04.000Z (almost 5 years ago)
- Last Synced: 2025-01-16T12:55:00.305Z (over 1 year ago)
- Topics: bug, error, planner, postgres, postgresql, sql, timescaledb
- Language: Shell
- Homepage: https://github.com/timescale/timescaledb/issues/3629
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Error with DISTINCT ON in HYPERTABLE
## How to reproduce in playground with docker compose
```bash
$ docker-compose up
```
The broken query:
```sql
SELECT DISTINCT ON (id) * FROM test
WHERE id IN (2)
ORDER BY id ASC, time DESC;
```
Correct result:
```sql
id | time | value
----+------------------------+------------
2 | 2021-10-01 15:00:00+00 | two-second
(1 row)
```
Error result:
```sql
ERROR: column not present in index: 1
```
Query doesn't work when array contains a single value and using a second parameter in order by condition.
If we have two or more values in `array` then query works.
If we remove second condition in `order by` then query works.
## Summary
| PostgreSQL version | TimescaleDB version | Status | Docker image |
| --- | --- | --- | --- |
| 11.13 | - | ✅ | postgres:11 |
| 12.8 | - | ✅ | postgres:12 |
| 13.4 | - | ✅ | postgres:13 |
| 11.12 | 2.3.1 | ❌ | timescale/timescaledb:latest-pg11 |
| 12.8 | 2.4.2 | ❌ | timescale/timescaledb:latest-pg12 |
| 13.4 | 2.4.2 | ❌ | timescale/timescaledb:latest-pg13 |
| 12.8 | 2.2.0 | ✅ | current production environment |
We have to rewrite our queries to `WITH` clause for TimescaleDB upgrade from `2.2.0` to the latest...