{"id":20531744,"url":"https://github.com/binakot/timescaledb-error-distinct-on-single-object-array-and-second-order-by","last_synced_at":"2026-04-11T20:35:30.520Z","repository":{"id":134569087,"uuid":"412370686","full_name":"binakot/timescaledb-error-distinct-on-single-object-array-and-second-order-by","owner":"binakot","description":"Bug report to TimescaleDB about broken 'distinct on'","archived":false,"fork":false,"pushed_at":"2021-10-01T07:32:04.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T12:55:00.305Z","etag":null,"topics":["bug","error","planner","postgres","postgresql","sql","timescaledb"],"latest_commit_sha":null,"homepage":"https://github.com/timescale/timescaledb/issues/3629","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binakot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-01T07:26:52.000Z","updated_at":"2023-10-13T10:32:16.000Z","dependencies_parsed_at":"2023-06-19T01:48:43.742Z","dependency_job_id":null,"html_url":"https://github.com/binakot/timescaledb-error-distinct-on-single-object-array-and-second-order-by","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binakot%2Ftimescaledb-error-distinct-on-single-object-array-and-second-order-by","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binakot%2Ftimescaledb-error-distinct-on-single-object-array-and-second-order-by/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binakot%2Ftimescaledb-error-distinct-on-single-object-array-and-second-order-by/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binakot%2Ftimescaledb-error-distinct-on-single-object-array-and-second-order-by/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binakot","download_url":"https://codeload.github.com/binakot/timescaledb-error-distinct-on-single-object-array-and-second-order-by/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242138800,"owners_count":20078007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bug","error","planner","postgres","postgresql","sql","timescaledb"],"created_at":"2024-11-16T00:09:32.367Z","updated_at":"2025-10-27T01:02:44.047Z","avatar_url":"https://github.com/binakot.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Error with DISTINCT ON in HYPERTABLE\n\n## How to reproduce in playground with docker compose\n\n```bash\n$ docker-compose up\n```\n\nThe broken query:\n\n```sql\nSELECT DISTINCT ON (id) * FROM test\nWHERE id IN (2)\nORDER BY id ASC, time DESC;\n```\n\nCorrect result:\n\n```sql\n id |          time          |   value\n----+------------------------+------------\n  2 | 2021-10-01 15:00:00+00 | two-second\n(1 row)\n```\n\nError result:\n\n```sql\nERROR:  column not present in index: 1\n```\n\nQuery doesn't work when array contains a single value and using a second parameter in order by condition.\nIf we have two or more values in `array` then query works.\nIf we remove second condition in `order by` then query works.\n\n## Summary\n\n| PostgreSQL version | TimescaleDB version | Status | Docker image |\n| --- | --- | --- | --- |\n| 11.13 | - | ✅ | postgres:11 |\n| 12.8 | - | ✅ | postgres:12 |\n| 13.4 | - | ✅ | postgres:13 |\n| 11.12 | 2.3.1 | ❌ | timescale/timescaledb:latest-pg11 |\n| 12.8 | 2.4.2 | ❌ | timescale/timescaledb:latest-pg12 |\n| 13.4 | 2.4.2 | ❌ | timescale/timescaledb:latest-pg13 |\n| 12.8 | 2.2.0 | ✅ | current production environment |\n\nWe have to rewrite our queries to `WITH` clause for TimescaleDB upgrade from `2.2.0` to the latest...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinakot%2Ftimescaledb-error-distinct-on-single-object-array-and-second-order-by","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinakot%2Ftimescaledb-error-distinct-on-single-object-array-and-second-order-by","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinakot%2Ftimescaledb-error-distinct-on-single-object-array-and-second-order-by/lists"}