CouchDB FDW (beta) for PostgreSQL 9.1+
This PostgreSQL extension implements a Foreign Data Wrapper (FDW) for
the CouchDB document-oriented database: http://couchdb.apache.org/
IMPORTANT: There're bugs in the existing version. I'm working on it and will
be releasing another version very soon.
To build the code, you need the yajl(Yet Another JSON Library) and libcurl installed
on your system.
You can checkout the yajl from GitHub:
libcurl C interface can be found here:
Once that's done, the extension can be built with:
PATH=/usr/local/pgsql91/bin/:$PATH make USE_PGXS=1 make
sudo PATH=/usr/local/pgsql91/bin/:$PATH make USE_PGXS=1 install
(assuming you have PostgreSQL 9.1 in /usr/local/pgsql91).
I've tested on Mac OS X 10.6 only, but other *nix's should also work.
I haven't tested on Windows, but the code should be good on MinGW.
- If there is no quals to pushdown, we get a list of '_id's to begin with,
and then fetch whatever records still exist as we build the tuples.
- We can only pushdown '_id' (with or without '_rev') to CouchDB, which must use
the TEXTEQ operator.
- The top-level-attributes of a document can be mapped to columns in a
- In case you want the map a column to the entire JOSN doc, use
in foreign table options (which means your remote couchdb shouldn't have
a top-level-attribute called '_doc', otherwise there will be conficts).
The following parameters can be set on a CouchDB foreign server:
address: The address or hostname of the CouchDB server.
port: The port number on which the CouchDB server is listening.
The following parameter can be set on a CouchDB foreign table:
database: The numeric ID of the CouchDB database to query.
<column name>: The column mapping to remote JSON attributes.
If there is no column mapping specified, default is the origninal column name.
Please note that '_doc' is reserved for mapping the entire JSON document.
The following parameter can be set on a user mapping for a CouchDB
username: The username to authenticate to the CouchDB server with.
password: The password to authenticate to the CouchDB server with.
CREATE SERVER couchdb_server
FOREIGN DATA WRAPPER couchdb_fdw
OPTIONS (address '127.0.0.1', port '5984');
CREATE FOREIGN TABLE couchdb_table (key text, value text)
OPTIONS (database 'testdb', key '_id', value '_doc');
CREATE USER MAPPING FOR PUBLIC
OPTIONS (username 'testuser', password 'secret');