Write PostgreSQL extension functions using Rust.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 8ab8184 Dec 3, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Add Result, Error, change PG version to 11 Nov 30, 2018
src Fix macros Nov 30, 2018
.gitignore Clear unused things Oct 30, 2018
Cargo.toml Clear unused things Oct 30, 2018
LICENSE Initial commit Oct 25, 2018
README.md Update README.md Dec 3, 2018
wrapper.h Add pg10 bindings using bindgen Oct 26, 2018



Write PostgreSQL extension functions (as stored procedures) using Rust.

Use the Fastest, Efficient, Safe, Enjoyable language, to write In-Database programs, for the World's Most Advanced Open Source Relational Database!

Code Example

extern crate pgxr;

use pgxr::bindings::*;



pub extern "C" fn pgxr_example_one(_fcinfo: FunctionCallInfo) -> Datum


git clone https://github.com/clia/pgxr.git
cd pgxr/examples/pgxr_example_one
cargo build --release

Then run pg_config

Find PKGLIBDIR, such as /usr/lib/postgresql/11/lib

sudo cp target/release/libpgxr_example_one.so /usr/lib/postgresql/11/lib
sudo su - postgres
CREATE FUNCTION pgxr_example_one() RETURNS integer
     AS 'libpgxr_example_one.so', 'pgxr_example_one'
select pgxr_example_one();


The included bindings.rs is for latest PostgreSQL version, current 11, on the Linux X86-64 arch. You can bindgen your platform's bindings.rs, using:

bindgen wrapper.h -o src/bindings.rs -- -I /usr/include/postgresql/11/server

Other platforms

This repo is for latest PostgreSQL version, current 11, on the Linux platform on X86-64 arch.

There are individual repos for each platform, listed below:

You can simply change the crate path in your Cargo.toml (No change the crate name pgxr) to develop for your target platform.

That is it.

Have fun!