Skip to content

Solution modifiers — DISTINCT / ORDER BY / LIMIT / OFFSET

The canonical SPARQL post-processing: DISTINCT, ORDER BY (asc/desc, type-aware), LIMIT, OFFSET.

What it does

The standard solution-sequence modifiers all run inside pgrdf.sparql — no need to wrap the call in an outer SQL SELECT … DISTINCT … ORDER BY … LIMIT.

ModifierEffect
DISTINCTDe-duplicate solutions.
ORDER BY ?v / ORDER BY DESC(?v)Type-aware ordering (numeric for typed numeric literals, lexical otherwise).
LIMIT nBound the result set size.
OFFSET nSkip the first n solutions.

ORDER BY accepts multiple keys, mixed asc/desc, and expressions: ORDER BY ?region DESC(?count) LCASE(?name).

Why you'd use it

  • Data scientists / app developers — pagination, deduplication, top-N ranking inside SPARQL.

Example

sql
SELECT * FROM pgrdf.sparql(
  'SELECT DISTINCT ?p
     WHERE { ?s ?p ?o }
   ORDER BY ?p LIMIT 20 OFFSET 100');

Tests

Apache-2.0 licensed. Documentation for pgRDF — built with VitePress, served via GitHub Pages.