Count of number of rows using dblink in postgresql

29 Views Asked by At

How to get the row count of a table in another database using dblink in postgresql function?

1

There are 1 best solutions below

0
Bert-Jan Stroop On
SELECT 
   * 
FROM 
   dblink('dbname=<db-name>','select count(*) as c from <schema>.<table>')
AS 
   t1(c int);

Just insert everything between < > with your own values. Ofcoarse also don't forget to include the extension on the machine from where you run the query, by running:

CREATE EXTENSION IF NOT EXISTS dblink;