Experimental Foreign Data Wrapper support for pgx.
- Impl the trait
pgx_fdw::ForeignData
struct MyFdw {}
impl pgx_fdw::ForeignData for MyFdw {
...
}
- 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()
}
- 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'
);
inmem_table
- Simple in-memory table fdw usingVec