Pillar 2 — Semantic query (SPARQL 1.1)
pgrdf.sparql(q TEXT) → SETOF JSONB parses SPARQL with spargebra, translates the algebra to dynamic SQL against the hexastore quad tables, executes it, and yields one JSONB row per solution.
Solution variables become JSONB keys; unbound variables come through as null.
Surface in this pillar
- BGP joins — N-pattern joins.
- FILTER — boolean composition + term-type tests.
- OPTIONAL — left outer join.
- UNION — disjoint pattern alternatives.
- MINUS — set difference.
- Aggregates —
COUNT,SUM,AVG,MIN/MAX,GROUP_CONCAT,SAMPLE. - HAVING — post-aggregate FILTER.
- BIND — project computed values.
- Solution modifiers —
DISTINCT,ORDER BY,LIMIT,OFFSET. - ASK — boolean queries.
- GRAPH
<iri> { … }— named-graph scoping. sparql_parse— inspect without executing.- Error-message contract — stable error prefixes.
- Forward edge (v0.5) — UPDATE, CONSTRUCT, property paths.
At a glance
sql
-- Multi-pattern join with a FILTER and a solution modifier.
SELECT * FROM pgrdf.sparql(
'PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?s ?n
WHERE { ?s foaf:name ?n .
?s <http://example.com/age> ?age
FILTER(?age >= 30) }
ORDER BY ?n LIMIT 50');