dblink extension in PostgreSQL

SELECT * FROM dblink(‘hostaddr=192.168.0.222 port=5432 dbname=testdb2 user=postgres password=postgres’,
‘SELECT user_name From people’) AS t(user_name text);
CREATE VIEW remote_people_user_name AS
SELECT * FROM dblink(‘hostaddr=192.168.0.222 port=5432 dbname=testdb2 user=postgres password=postgres’,
‘SELECT user_name From people’) AS t(user_name text);
SELECT * FROM remote_people_user_name;
  1. First execute dblink_connect to keep connected

SELECT dblink_connect(‘connection’,’hostaddr=192.168.0.222 port=5432 dbname=testdb2 user=postgres password=postgres’);

SELECT dblink_exec(‘connection’,’BEGIN’);

SELECT dblink_exec(‘connection’,’insert… data manipulation’);

SELECT dblink_exec(‘connection’,’COMMIT’);
SELECT dblink_disconnect(‘connection’);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pankaj kushwaha

Pankaj kushwaha

Database/System Administrator | DevOPS | Cloud Specialist | DevOPS