sparql

pgsparql : Query SPARQL datasource with SQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4470
sparql
pgsparql
1.0
UTIL
Apache-2.0
SQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
----d--
No
No
No
Yes
no
no
Relationships
Schemassparql
Requires
plperl
plperlu
See Also
pgjq
pgjwt
gzip
bzip
zstd
http
pg_net
pg_curl

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
1.0
18
17
16
15
14
pgsparqlplperl, plperlu
RPM
PIGSTY
1.0
18
17
16
15
14
pgsparql_$v-
DEB
PIGSTY
1.0
18
17
16
15
14
postgresql-$v-pgsparql-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el8.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
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

Source

pig build pkg pgsparql;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pgsparql;		# install via package name, for the active PG version
pig install sparql;		# install by extension name, for the current active PG version

pig install sparql -v 18;   # install for PG 18
pig install sparql -v 17;   # install for PG 17
pig install sparql -v 16;   # install for PG 16
pig install sparql -v 15;   # install for PG 15
pig install sparql -v 14;   # install for PG 14

Create this extension with:

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 updated on