sparql

Query SPARQL datasource with SQL

Overview

PackageVersionCategoryLicenseLanguage
pgsparql1.0UTILApache-2.0SQL
IDExtensionBinLibLoadCreateTrustRelocSchema
4470sparqlNoNoNoYesNoNosparql
Relatedplperl plperlu pgjq pgjwt gzip bzip zstd http pg_net pg_curl

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.01817161514pgsparqlplperl, plperlu
RPMPIGSTY1.01817161514pgsparql_$v-
DEBPIGSTY1.01817161514postgresql-$v-pgsparql-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

Build

You can build the RPM / DEB packages for pgsparql using pig build:

pig build pkg pgsparql         # build RPM / DEB packages

Install

You can install pgsparql directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pgsparql;          # Install for current active PG version
pig ext install -y pgsparql -v 18  # PG 18
pig ext install -y pgsparql -v 17  # PG 17
pig ext install -y pgsparql -v 16  # PG 16
pig ext install -y pgsparql -v 15  # PG 15
pig ext install -y pgsparql -v 14  # PG 14
dnf install -y pgsparql_18       # PG 18
dnf install -y pgsparql_17       # PG 17
dnf install -y pgsparql_16       # PG 16
dnf install -y pgsparql_15       # PG 15
dnf install -y pgsparql_14       # PG 14
apt install -y postgresql-18-pgsparql   # PG 18
apt install -y postgresql-17-pgsparql   # PG 17
apt install -y postgresql-16-pgsparql   # PG 16
apt install -y postgresql-15-pgsparql   # PG 15
apt install -y postgresql-14-pgsparql   # PG 14

Create Extension:

CREATE EXTENSION sparql CASCADE;  -- requires: plperl, plperlu

Usage

sparql: SPARQL query support for PostgreSQL

Query SPARQL endpoints (e.g., DBpedia/Virtuoso) from PostgreSQL. SPARQL queries are compiled into Postgres views for use in SQL.

Get Properties of a Resource

SELECT * FROM sparql.get_properties('dbpedia', 'http://dbpedia.org/resource/Johann_Sebastian_Bach');

Get References to a Resource

SELECT * FROM sparql.get_references('dbpedia', 'http://dbpedia.org/resource/Johann_Sebastian_Bach');

Compile SPARQL Query into SQL View

SELECT sparql.compile_query(endpoint, identifier, sparql_query [, grouping]);

Parameters:

  • endpoint – default SPARQL endpoint name
  • identifier – SQL identifier for the created function and view
  • sparql_query – the SPARQL query to compile
  • grouping – optional array of identifiers to group by (non-grouped columns are aggregated into arrays)

Example

SELECT sparql.compile_query('dbpedia', 'ludwig_van', $$
  SELECT ?predicate, ?object
  WHERE {
    <http://dbpedia.org/resource/Ludwig_van_Beethoven> ?predicate ?object.
  }
$$, '{predicate}');

-- Now query via the created view
SELECT * FROM ludwig_van;

This creates a function ludwig_van() and a view ludwig_van that queries the SPARQL endpoint and returns results as a SQL table.


Last Modified 2026-03-12: add pg extension catalog (95749bf)