Skip to content

Fix: Sort observations by resultTime in descending order#19

Open
ram-from-tvl wants to merge 1 commit into52North:mainfrom
ram-from-tvl:fix/sort-observations-by-resulttime
Open

Fix: Sort observations by resultTime in descending order#19
ram-from-tvl wants to merge 1 commit into52North:mainfrom
ram-from-tvl:fix/sort-observations-by-resulttime

Conversation

@ram-from-tvl
Copy link

@ram-from-tvl ram-from-tvl commented Feb 26, 2026

Fixes #5

Changes Made

Added ORDER BY resulttime DESC clause to the SQL query in the ObservationQuery.to_sql() method (util.py).

This ensures observations are returned in descending order by resultTime, with the newest observations appearing first.

Why This Approach

  • The sorting is applied at the database level (TimescaleDB/PostgreSQL) for optimal performance
  • Using resultTime as the sort key aligns with the observation data model
  • Descending order (newest first) is the most common use case for time-series data
  • The ORDER BY clause is placed before LIMIT/OFFSET to ensure proper pagination

Resolves #5

Resolves 52North#5 - Observations are now returned sorted by resultTime DESC,
ensuring newest observations appear first for consistent pagination.
Copilot AI review requested due to automatic review settings February 26, 2026 11:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds sorting functionality to observation queries by implementing an ORDER BY resulttime DESC clause at the database level. The change addresses issue #5, which reported that observations were being returned in an unsorted order, making it difficult for API consumers to work with time-series data predictably.

Changes:

  • Added ORDER BY resulttime DESC to the SQL query builder in ObservationQuery.to_sql() method to ensure all observation queries return results sorted by newest first

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ram-from-tvl
Copy link
Author

Hi @EHJ-52n @SpeckiJ
please review this PR and let me know if more changes are required.
Thankyou!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observations are not sorted

2 participants