rdf_fdw
rdf_fdw : Foreign data wrapper for RDF triplestores over SPARQL endpoints
Overview
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pgrdf ogr_fdw sparql nominatim_fdw postgis mongo_fdw redis_fdw etcd_fdw xml2 plxslt |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.7.0 |
18 17 16 15 14 | rdf_fdw |
- |
| RPM | PIGSTY | 2.7.0 |
18 17 16 15 14 | rdf_fdw_$v |
- |
| DEB | PIGSTY | 2.7.0 |
18 17 16 15 14 | postgresql-$v-rdf-fdw |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| el8.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| el9.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| el9.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| el10.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| el10.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| d12.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| d12.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| d13.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| d13.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u22.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u22.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u24.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u24.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u26.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u26.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
Source
github.com/jimjonesbr/rdf_fdw
rdf_fdw-2.7.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
rdf_fdw is a PostgreSQL foreign data wrapper for querying RDF triplestores over SPARQL endpoints. It exposes SPARQL result variables as foreign-table columns, supports pushdown for common SQL clauses, includes a native rdfnode type for RDF terms, provides SPARQL 1.1 helper functions, and can perform SPARQL INSERT, UPDATE, and DELETE through writable foreign tables.
v2.6.0 adds Bearer-token authentication through USER MAPPING, a max_response_size server option to cap HTTP response bodies, BCE date/timestamp cast handling, and many rdfnode parser/comparison fixes. v2.7 fixes RDF literal escaping for runs of trailing backslashes so literal content cannot break out into generated SPARQL syntax. It also initializes libcurl once per PostgreSQL backend instead of once per request.
Create the Extension
To install or update to the exact SQL version:
Register a SPARQL Endpoint
Useful server options include:
endpoint: SPARQL endpoint URL; required.batch_size: number of rows per SPARQL UPDATE batch.enable_pushdown: enables SQL-to-SPARQL pushdown.format: expected SPARQL result MIME type.http_proxy: proxy URL; proxy credentials belong inUSER MAPPING.connect_timeout: connection timeout.request_timeout: complete HTTP request timeout.max_response_size: maximum response body size in bytes;0means unlimited.readonly: preventsINSERT,UPDATE, andDELETEbefore requests reach the endpoint.request_redirectandrequest_max_redirect: redirect behavior.
Use max_response_size for public or untrusted endpoints because rdf_fdw loads retrieved RDF data into memory before converting it for PostgreSQL.
User Mapping
v2.6.0 adds Bearer-token authentication:
Proxy credentials are also USER MAPPING options:
Foreign Tables with rdfnode Columns
Declare foreign-table columns as rdfnode to preserve RDF terms, IRIs, blank nodes, language tags, and XSD datatypes.
Native PostgreSQL column types are deprecated for RDF values in v2.6.0. Existing native-typed tables continue to work, but they emit warnings and lose RDF term details.
Querying and Pushdown
rdf_fdw can push down WHERE, LIMIT, ORDER BY, DISTINCT, and supported comparisons/functions. Use EXPLAIN VERBOSE to inspect the generated remote SPARQL.
Prefix Management
rdf_fdw provides catalog tables and helper functions under the sparql schema for reusable SPARQL prefixes:
Data Modification
Writable foreign tables can translate PostgreSQL INSERT, UPDATE, and DELETE into SPARQL UPDATE requests when the foreign table has the required SPARQL update pattern.
Use readonly = true at the server or table level when an endpoint should never receive writes.
Clone a Foreign Table
rdf_fdw_clone_table() copies data from a foreign table into a local table in batches. v2.5 fixed several round-trip issues for RDF terms during cloning.
SPARQL Functions
The sparql schema implements many SPARQL 1.1 functions and aggregates, including:
- aggregates such as
sparql.sum,sparql.avg,sparql.min,sparql.max,sparql.group_concat, andsparql.sample - RDF term helpers such as
sparql.isiri,sparql.isblank,sparql.isliteral,sparql.datatype,sparql.iri,sparql.strdt, andsparql.strlang - string functions such as
sparql.strlen,sparql.substr,sparql.ucase,sparql.lcase,sparql.contains, andsparql.replace - numeric, date/time, hash, and custom convenience functions
Caveats
- PostgreSQL 9.5 or newer is the upstream baseline.
- Retrieved RDF data is accumulated in memory before conversion. Set
max_response_size, useLIMIT, and keep remote result sets bounded. - Prefer
rdfnodecolumns. Native PostgreSQL typed columns are deprecated for RDF terms and will lose IRI/language/datatype information. - Store secrets in
USER MAPPING; do not put proxy credentials or endpoint tokens intoSERVERoptions. - Public SPARQL endpoints can be slow or rate-limited. Use
connect_timeout,request_timeout, retries, and local materialization when needed. - Upgrade to 2.7 before accepting untrusted literal content in pushed-down filters or writable foreign-table operations; the libcurl lifecycle fix is internal and adds no new SQL configuration.