Steve Robinson
Steve Robinson

Reputation: 46

Postgres Foreign Data Wrapper Aggregate function pushdown

Situation:

Issue:

My question:

Is it possible to "push down" this aggregate function so that the count(*) is performed on the remote postgres database?

Upvotes: 2

Views: 984

Answers (2)

klin
klin

Reputation: 121754

If you do not want to wait for Postgres 10, use this workaround:

Create a view in the foreign database:

-- in db1:
create view count_my_table as (
    select count(*) 
    from foreign_table);

Create a foreign table for the view in the local database:

-- in db2:
create foreign table count_my_table (
    count bigint
)
server foreign_server
options (table_name 'count_my_table');

select count 
from count_my_table;

Upvotes: 1

Steve Robinson
Steve Robinson

Reputation: 46

I'm going to go ahead and answer my own question.

Aggregate pushdown for foreign tables will be coming in postgres 10.

See https://www.enterprisedb.com/blog/postgresql-aggregate-push-down-postgresfdw for details.

Upvotes: 0

Related Questions