diff options
Diffstat (limited to 'contrib/dblink/doc/query')
-rw-r--r-- | contrib/dblink/doc/query | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/contrib/dblink/doc/query b/contrib/dblink/doc/query new file mode 100644 index 00000000000..525ffab45a2 --- /dev/null +++ b/contrib/dblink/doc/query @@ -0,0 +1,85 @@ +================================================================== +Name + +dblink -- Returns a set from a remote database + +Synopsis + +dblink(text connstr, text sql) +- or - +dblink(text sql) + +Inputs + + connstr + + standard libpq format connection string, + e.g. "hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd" + If the second form is used, then the dblink_connect(text connstr) must be + executed first. + + sql + + sql statement that you wish to execute on the remote host + e.g. "select * from pg_class" + +Outputs + + Returns setof record + +Example usage + +test=# select * from dblink('dbname=template1','select proname, prosrc from pg_proc') + as t1(proname name, prosrc text) where proname like 'bytea%'; + proname | prosrc +------------+------------ + byteacat | byteacat + byteaeq | byteaeq + bytealt | bytealt + byteale | byteale + byteagt | byteagt + byteage | byteage + byteane | byteane + byteacmp | byteacmp + bytealike | bytealike + byteanlike | byteanlike + byteain | byteain + byteaout | byteaout +(12 rows) + +test=# select dblink_connect('dbname=template1'); + dblink_connect +---------------- + OK +(1 row) + +test=# select * from dblink('select proname, prosrc from pg_proc') + as t1(proname name, prosrc text) where proname like 'bytea%'; + proname | prosrc +------------+------------ + byteacat | byteacat + byteaeq | byteaeq + bytealt | bytealt + byteale | byteale + byteagt | byteagt + byteage | byteage + byteane | byteane + byteacmp | byteacmp + bytealike | bytealike + byteanlike | byteanlike + byteain | byteain + byteaout | byteaout +(12 rows) + +================================================================== +A more convenient way to use dblink may be to create a view: + + create view myremote_pg_proc as + select * + from dblink('dbname=template1','select proname, prosrc from pg_proc') + as t1(proname name, prosrc text); + +Then you can simply write: + + select * from myremote_pg_proc where proname like 'bytea%'; + |