Re: extra function calls from query returning composite type

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ron(at)yellowbank(dot)com, Ronald Peterson <ron(at)hub(dot)yellowbank(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: extra function calls from query returning composite type
Date: 2014-12-29 15:54:49
Message-ID: 6792.1419868489@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ronald Peterson <ron(at)hub(dot)yellowbank(dot)com> writes:
> I added a 'raise notice' to a plpgsql function I was working on
> recently, and noticed that my notification was being raised more often
> than I expected. The notification is raised in a function ('getone'
> in my example below) that returns a single composite value. This
> function is then called by another function ('getset') that returns a
> setof that composite value. It appears that 'getone' is called once
> for each column of my composite type. I whittled this down to the
> following example.

> I get the expected result from my query, but I don't understand (what
> appear to be) the extra function calls.

This:

> SELECT (getone(id)).*

is implemented as SELECT (getone(id)).foo, (getone(id)).bar

If you're using 9.3 or later you could avoid that by recasting the
call as LATERAL, ie

SELECT go.*
FROM dat, LATERAL getone(id) AS go
WHERE set = setid;

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2014-12-29 15:59:52 Re: Rollback on include error in psql
Previous Message David G Johnston 2014-12-29 15:54:00 Re: extra function calls from query returning composite type