Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
100 lines (68 sloc) 2.82 KB
CouchDB FDW (beta) for PostgreSQL 9.1+
This PostgreSQL extension implements a Foreign Data Wrapper (FDW) for
the CouchDB document-oriented database:
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:
download from:
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
foreign table.
- In case you want the map a column to the entire JOSN doc, use
columnname '_doc'
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.
Default: 5984
The following parameter can be set on a CouchDB foreign table:
database: The name of the CouchDB database to query.
Default: test
<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
foreign server:
username: The username to authenticate to the CouchDB server with.
Default: <none>
password: The password to authenticate to the CouchDB server with.
Default: <none>
CREATE SERVER couchdb_server
OPTIONS (address '', port '5984');
CREATE FOREIGN TABLE couchdb_table (key text, value text)
SERVER couchdb_server
OPTIONS (database 'testdb', key '_id', value '_doc');
SERVER couchdb_server
OPTIONS (username 'testuser', password 'secret');
Zheng Yang