Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 994 Bytes

README.md

File metadata and controls

43 lines (35 loc) · 994 Bytes

pgx-fdw

Experimental Foreign Data Wrapper support for pgx.

Implementing a FDW

  1. Impl the trait pgx_fdw::ForeignData
struct MyFdw {}
impl pgx_fdw::ForeignData for MyFdw {
    ...
}
  1. Create handler function
/// ```sql
/// CREATE FUNCTION my_handler() RETURNS fdw_handler LANGUAGE c AS 'MODULE_PATHNAME', 'my_handler_wrapper';
/// ```
#[pg_extern]
fn my_handler() -> pg_sys::Datum {
    pgx_fdw::FdwState::<MyFdw>::into_datum()
}
  1. Create wrapper + server
CREATE FOREIGN DATA WRAPPER my_handler handler my_handler NO VALIDATOR;
CREATE SERVER my_fdw_srv FOREIGN DATA WRAPPER my_handler OPTIONS (server_option '1', server_option '2');
CREATE FOREIGN TABLE users (
    id text,
    name text,
    email text
) SERVER my_fdw_server OPTIONS (
    table_option '1',
    table_option2 '2'
);

Examples

  • inmem_table - Simple in-memory table fdw using Vec