Skip to content

Conversation

@Chengxuan
Copy link
Contributor

@Chengxuan Chengxuan commented Jan 13, 2026

This PR adds support for PostgreSQL's DISTINCT ON clause to the firefly-common library, enabling efficient querying of distinct rows based on specific field combinations. This feature is PostgreSQL-specific and provides a more performant alternative to using GROUP BY or subqueries for deduplication scenarios.

Postgres ONLY

The feature explicitly validates that the database provider is PostgreSQL before applying DISTINCT ON, returning a clear error message for unsupported providers.

Usage Example

filter := queryFactory.NewFilter(ctx).
    DistinctOn("namespace", "type").
    Sort("created").
    And()

results, _, err := collection.GetMany(ctx, filter)

This generates SQL like:

SELECT DISTINCT ON (namespace, type) * 
FROM table 
ORDER BY namespace, type, created

Signed-off-by: Chengxuan Xing <chengxuan.xing@kaleido.io>
@Chengxuan Chengxuan requested a review from a team as a code owner January 13, 2026 12:01
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.

1 participant