pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

[Question] Foreign Data Wrapper

Open if0ne opened this issue 6 months ago • 8 comments

Is there any plan to create a safe abstraction for creating a foreign data wrapper?

I know that there are crate wrappers, but why not move this framework to the pgrx repository?

if0ne avatar Jul 16 '25 11:07 if0ne

That repo hosts several readymade FDWs and we would be pretty uninterested in maintaining various wrappers between various different DBs.

workingjubilee avatar Oct 28 '25 03:10 workingjubilee

granted, if @burmecia wants to upstream some code, pretty sure we'll take some of it, but I don't see us adopting it wholesale.

workingjubilee avatar Oct 28 '25 05:10 workingjubilee

I'm more interested in the safe abstraction of FDW because FDW FFI looks verbose.

if0ne avatar Oct 28 '25 07:10 if0ne

that'd be great if we can upstream the wrappers framework. Although there are some code for specific use, it should be possible to port the generic interface to upstream. Do you have ideas what kind of safe abstraction do you want to see in pgrx?

burmecia avatar Oct 28 '25 11:10 burmecia

For my purposes, the current design of the ForeignDataWrapper trait and the wrappers_fdw macro is sufficient.

if0ne avatar Oct 28 '25 12:10 if0ne

I'm not too picky here I think about overall design, but I might need to better understand the lifetimes involved in FDWs and to what extent what things are modeled.

workingjubilee avatar Oct 28 '25 21:10 workingjubilee

@burmecia For example, one of the things I'm curious about is supabase_wrappers::interface::Cell. It seems like a type that is fully "lifted" from... Postgres(?) into Rust. I'm not sure why this highly abstracted type that allows essentially anything to be dynamically present is used instead of something static. External databases do allow highly dynamic typing, but Postgres is a bit more strict on these sorts of things, which helps pgrx greatly.

There is probably a good reason, but the repo lacks a description of these sorts of "high-level" decisions. I can't find it either in something like an ARCHITECTURE.md or type-level documentation. There is some documentation hosted on https://fdw.dev but it only goes into "what is a foreign data wrapper", not so much the specifics.

workingjubilee avatar Nov 02 '25 19:11 workingjubilee

Those types in supabase_wrappers::interface::Cell are mainly to provide a simplified type abstraction for developers, so they don't need to directly talk with pgrx types. It originally only covered a small subset of pgrx types, but gradually expanded later on. If they are moved to pgrx, I don't think that abstraction is needed and can be built on pgrx types directly.

burmecia avatar Nov 18 '25 01:11 burmecia