You have two basic options, well three basic ones rather.
The first is to use DBI-Link
and then access this via your pl/pgsql or pl/perl function. The nice thing about DBI-Link
is that it is relatively older and mature. If it works for you I would start there.
The second option is to use foreign data wrappers.
The third option is to write a more general framework in something like pl/perl
that you can call from pl/pgsql
. However at that point you are basically looking at re-inventing DBI-Link so I think you are better off starting with DBI-Link and modifying it as needed.