X
Xata2mo ago
matdehaast

pgvx: complex return types

I love what you have done with pgzx. I'm trying to work out how I would produce complex return types of custom functions. Can I just return a pg Datum? Or is there more to it? Thanks matt
1 Reply
Urso
Urso2mo ago
You can always return a Datum if you find automatic conversion too limiting. If you want nullable you can return ?Datum. In that case a null will be correctly translated into a Datum. When implementing a function with pgzx we use compile time reflection for primitive types via pgzx.datum.findConv . The findConv function also checks if your type implements fromNullableDatum and toNullableDatum (although the check could be more exhaustive and allow more type patterns in the future). An example from this blog post: https://xata.io/blog/pgzx-update-0.2.0
fn pgdc_fdw_handler() pg.Datum {
return pg.PointerGetDatum(pgzx.node.create(pg.FdwRoutines{
.BeginForeignScan = ...,
.IterateForeignScan = ...,
.EndForeignScan = ...,
...
}));
}
fn pgdc_fdw_handler() pg.Datum {
return pg.PointerGetDatum(pgzx.node.create(pg.FdwRoutines{
.BeginForeignScan = ...,
.IterateForeignScan = ...,
.EndForeignScan = ...,
...
}));
}
pgzx: Version 0.2.0 update
Learn about the latest changes in pgzx
Want results from more Discord servers?
Add your server