Skip to content

FILTER — boolean composition over solutions

Equality, ordering, boolean composition, term-type tests, bound, in, regex, numeric comparison, string functions.

What it does

A FILTER expression evaluates a boolean over each candidate solution; only the truthy solutions survive. pgRDF supports the full SPARQL 1.1 expression surface that the underlying spargebra algebra and the executor can translate to SQL:

ClassOperators / functions
Comparison=, !=, <, <=, >, >=
Boolean&&, ||, !
Term-type testsisIRI, isLiteral, isBlank, isNumeric
Binding testsbound(?v)
Set tests?v IN (a, b, c), ?v NOT IN (...)
RegexREGEX(?v, "pat", "flags")
Numerictype-aware on xsd:integer, xsd:decimal, xsd:double
StringSTRLEN, UCASE, LCASE, STR, LANG

Why you'd use it

  • Data scientists — apply text-search and numeric predicates inside the SPARQL pattern, not in a post-process.
  • Ontologists — carve subgraphs declaratively without writing SQL CASE ladders.

Example

sql
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 && REGEX(?n, "^A", "i")) }');

Term-type filter:

sql
SELECT * FROM pgrdf.sparql(
  'PREFIX foaf: <http://xmlns.com/foaf/0.1/>
   SELECT ?s ?o
     WHERE { ?s ?p ?o FILTER(isIRI(?o) && ?p = foaf:knows) }');

Tests

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