sparql_fdw is a foreign data wrapper for PostgreSQL to access sparql data from within PostgreSQL alike a normal table.
2025-10-12 16:03:05 +02:00
sparqlfdw Changed the documentation to use multicorn2 instead of multicorn. Corrected some misused tabs and tested it against several PostgreSQL versions. 2022-08-04 16:13:25 +02:00
test first commit 2018-08-05 21:59:26 +02:00
.gitignore first commit 2018-08-05 21:59:26 +02:00
LICENSE.md According to the package info, the code is under the PostgreSQL license. Therefore I added the license to the repo. 2022-08-05 10:35:15 +02:00
README.md Tested the extension succesfully against PostgreSQL 18. 2025-10-12 16:03:05 +02:00
setup.py Changed the documentation to use multicorn2 instead of multicorn. Corrected some misused tabs and tested it against several PostgreSQL versions. 2022-08-04 16:13:25 +02:00

Sparql FDW for PostgreSQL

sparql_fdw is experimantal code, use it at your own risk. But please consider to open a bug report on the Github repository, if you stumble upon something, that doesn't work as expected.

PostgreSQL support

version version version version version version

Lang [![PostgreSQL](hversion ttps://img.shields.io/badge/License-PostgreSQL-green.svg)]() Extension

Installation

Installation of multicorn

As the original multicorn sources are somewhat outdated, use multicorn2 instead. Please follow the installation guide on https://github.com/pgsql-io/multicorn2

CentOS/RockyLinux install with postgresql installed from PGDG repository

Installation of needed packages

yum install -y epel-release
yum install -y python3-setuptools git python3-pip python3-dateutil
pip3 install --break-system-packages --upgrade pip
pip3 install --break-system-packages SPARQLWrapper python-dateutil

Clone and execute 'python setup.py install' as root

git clone https://github.com/al1radix/sparql_fdw.git
cd sparql_fdw
python3 setup.py install

Debian/Ubuntu installation

Install needed Python packages

sudo apt install -y python3-setuptools git python3-pip python3-dateutil
sudo pip3 install --break-system-packages --upgrade pip
sudo pip3 install --break-system-packages SPARQLWrapper python-dateutil
pip3 install --break-system-packages python-dateutil

Clone sparql_fdw and instll it with pip3

git clone https://github.com/al1radix/sparql_fdw.git
cd sparql_fdw
sudo pip3 install --break-system-packages .

Usage

create multicorn extension

create extension multicorn;

create server

CREATE server wikidata foreign data wrapper multicorn
	options ( wrapper 'sparqlfdw.SparqlForeignDataWrapper', endpoint 'https://query.wikidata.org/sparql');

CREATE server dbpedia foreign data wrapper multicorn options ( wrapper 'sparqlfdw.SparqlForeignDataWrapper', endpoint 'http://dbpedia.org/sparql' );

Create foreign tables with sparql query

  • matching is done between table's column names and sparql selected variables names
-- eyes colors from wikidata
CREATE FOREIGN TABLE eyes ( "eyeColorLabel" json, count int, rien text )
server wikidata options ( sparql '
	SELECT ?eyeColorLabel (COUNT(?human) AS ?count)
	WHERE { ?human wdt:P31 wd:Q5.  ?human wdt:P1340 ?eyeColor.
	SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
	GROUP BY ?eyeColorLabel
')
;

The actual implementation is simplist and dosn't push down restriction, group by, order by nor limit to sparql