Re: dblink: add polymorphic functions.

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: dblink: add polymorphic functions.
Date: 2015-07-29 20:51:27
Message-ID: CAHyXU0yqreh8biDN5G-i1Sv=JG85do5o9QZ=6NqnZaPtYgUGqg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jul 29, 2015 at 12:53 PM, Joe Conway <mail(at)joeconway(dot)com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 07/29/2015 09:40 AM, Corey Huinker wrote:
>> Say I've got a table my_partitioned_table (key1 integer, key2
>> integer, metric1 integer, metric2 integer);
>>
>> And I've got many partitions on that table. My code lets you do
>> something like this:
>>
>> select key1, key2, sum(metric1) as a_sum_of_sums, sum(metric2) as
>> another_sum_of_sums from
>> execute_buncha_queries(null::my_partitioned_table,
>> 'connection_string_thats_just_a_loopback', array['select key1,
>> key2, sum(metric1), sum(metric2) from my_partition_p1 group by
>> 1,2', 'select key1, key2, sum(metric1), sum(metric2) from
>> my_partition_p2 group by 1,2', ...]) group by 1,2
>
>> I can't put a cast around execute_buncha_queries because the
>> function won't know how to cast the results coming back from
>> dblink.
>
> Ok, gotcha. So Tom's nearby comment about allowing the
> "p_rowtype%TYPE" syntax to be used in the CAST is spot on (as usual).
> In other words, to get a complete solution for you we would need to
> make both things work, so you could do this inside plpgsql:
>
> select * from cast(dblink(connstr, sql) as p_rowtype%TYPE);

Would this be a pl/pgsql only solution?

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Karlsson 2015-07-29 20:54:55 Re: Improving test coverage of extensions with pg_dump
Previous Message Robert Haas 2015-07-29 20:49:31 Re: Typo in a comment in set_foreignscan_references