Re: join between a table and function.

From: David Johnston <polobo(at)yahoo(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: join between a table and function.
Date: 2011-08-17 02:57:19
Message-ID: B9A04DA6-BE27-46B0-BAED-99E22AE1AB90@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Aug 16, 2011, at 14:29, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:

> On Tue, Aug 16, 2011 at 8:33 AM, Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com> wrote:
>> In article <CAKWoFMJWZ3znXCj9rADn4ov+krsa-133968YvAg3L8M3W3zyQQ(at)mail(dot)gmail(dot)com>,
>> Lauri Kajan <lauri(dot)kajan(at)gmail(dot)com> writes:
>>
>>> I have also tried:
>>> select
>>> *, getAttributes(a.id)
>>> from
>>> myTable a
>>
>>> That works almost. I'll get all the fields from myTable, but only a
>>> one field from my function type of attributes.
>>> myTable.id | myTable.name | getAttributes
>>> integer | character | attributes
>>> 123 | "record name" | (10,20)
>>
>>> What is the right way of doing this?
>>
>> If you want the attributes parts in extra columns, use
>>
>> SELECT *, (getAttributes(a.id)).* FROM myTable a
>
> This is not generally a good way to go. If the function is volatile,
> you will generate many more function calls than you were expecting (at
> minimum one per column per row). The best way to do this IMO is the
> CTE method (as david jnoted) or, if and when we get it, 'LATERAL'.
>

From your statement is it correct to infer that a function defined as "stable" does not exhibit this effect? More specifically would the function only be evaluated once for each set of distinct parameters and the resulting records(s) implicitly cached just like the CTE does explicitly?

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Siva Palanisamy 2011-08-17 04:55:05 Re: How to give \COPY inside a function
Previous Message Chris Travers 2011-08-16 23:14:14 Re: Using Postgresql as application server