searchPillar 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.
pgrdf.sparql also dispatches UPDATE forms (INSERT, DELETE, MODIFY, lifecycle algebra) inside the caller's transaction — the read and write surface share a single UDF entry point.
Read surface
- search BGP joins — N-pattern joins.
- search FILTER — boolean composition + term-type tests.
- hub OPTIONAL — left outer join.
- hub UNION — disjoint pattern alternatives.
- hub MINUS — set difference.
- query_stats Aggregates —
COUNT,SUM,AVG,MIN/MAX,GROUP_CONCAT,SAMPLE. - query_stats HAVING — post-aggregate FILTER.
- search BIND — project computed values.
- search Solution modifiers —
DISTINCT, type-awareORDER BY,LIMIT,OFFSET. - search VALUES — inline bindings as a solution source.
- search ASK — boolean queries.
- account_tree GRAPH
<iri> { … }— named-graph scoping (literal + variable forms). - hub Property paths —
^+*?\|with cycle-safe recursion + materialised-closure fast path.
Write surface
- code SPARQL UPDATE —
INSERT DATA,DELETE DATA, pattern-drivenINSERT/DELETE WHERE, atomicDELETE+INSERT/WHERE, graph-scopedWITHand inlineGRAPH, plus lifecycleDROP / CLEAR / CREATE GRAPH. - code CONSTRUCT —
pgrdf.construct(q) → SETOF JSONB; templates (constant / variable / blank-node / multi-triple), GRAPH-scoped WHERE, WHERE-shorthand, round-trip ingest. - code DESCRIBE —
pgrdf.describe(q) → SETOF JSONB; the W3C SPARQL 1.1 §16.4 Concise Bounded Description of one or more resources.
Diagnostics
- info
sparql_parse— inspect parsed shape (read + write + paths) without executing. - info Error-message contract — stable error prefixes.
- rocket_launch Forward edge — what's next — the complete SPARQL surface plus the v0.6 forward plan.
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');auto_storiesTraining
The SPARQL pillar splits naturally into three learning loops. Take them in order — each loop builds on the previous one:
Loop 1 — Read fundamentals
- search BGP joins — N triple patterns become an N-way self-join. The core primitive.
- search FILTER — once you can write a BGP, filtering it is the next leverage.
- search Solution modifiers + ASK — DISTINCT, ORDER BY, LIMIT, OFFSET, plus existence checks.
Loop 2 — Composition
- hub OPTIONAL — left outer join semantics; everything sparse-data needs.
- hub UNION + MINUS — alternation and set difference.
- query_stats Aggregates + HAVING + BIND — grouping, post-aggregate filtering, computed projections.
- account_tree GRAPH clause — named-graph scoping (literal + variable forms, composition with all the above).
Loop 3 — Write surface + diagnostics
- code SPARQL UPDATE — once you can read, the same UDF dispatches the six write forms.
- code CONSTRUCT — read-side counterpart to UPDATE's template-from-pattern shape.
- hub Property paths —
^+*?\|; the materialised-closure fast path is where inference and query pay each other back. - info sparql_parse + Error-message contract — programmatic shape inspection and stable error prefixes for tooling.
Learn more
- school The SPARQL 1.1 Query Language and Update specs.
- school Bob DuCharme's Learning SPARQL book — the practitioner's reference.
- code The
spargebracrate — the algebra layer pgRDF parses against. - mic Audio companion — fourteen episodes covering every SPARQL feature on this page (see Training).