Skip to content

Conversation

nirolevy
Copy link

Overview

This Pull Request resolves an issue with inconsistent paging when running CSW GetRecords requests against a PostgreSQL backend that utilizes SortBy on a non-unique field (e.g., dc:date).

When multiple records share the same value for the sort field, PostgreSQL's tie-breaker is non-deterministic, causing records to be included in more than one page when pagination (LIMIT/OFFSET) is used.

The fix introduces a configuration option to enable a stable sort by automatically appending the unique record identifier (pycsw:Identifier) to the ORDER BY clause of the database query. This ensures a consistent and deterministic order for all records, guaranteeing reliable pagination.

Related Issue / Discussion

Fixes: #1155

Additional Information

A new configuration option, stable_sort, has been added to the [repository] section of the configuration file.

To enable the fix, set stable_sort to true (it defaults to false for backwards compatibility):

repository:
  database: # Your database connection string
  table: records
  stable_sort: true

Contributions and Licensing

(as per https://github.com/geopython/pycsw/blob/master/CONTRIBUTING.rst\#contributions-and-licensing)

  • I'd like to contribute bugfix to pycsw. I confirm that my contributions to pycsw will be compatible with the pycsw license guidelines at the time of contribution.
  • I have already previously agreed to the pycsw Contributions and Licensing Guidelines

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.

Inconsistent Paging in PostgreSQL with Non-Unique SortBy

1 participant