Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] Returning a RECORD, not SETOF RECORD

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Thomas Hallgren <thhal(at)mailblocks(dot)com>,pgsql-hackers(at)postgresql(dot)org
Subject: Re: [GENERAL] Returning a RECORD, not SETOF RECORD
Date: 2005-04-29 17:21:35
Message-ID: 20050429172135.GA2695@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackers
On Fri, Apr 29, 2005 at 10:36:05AM -0400, Tom Lane wrote:
>
> regression=# select (xyz(unique1,unique2)).* from tenk1 limit 5;

This is a little off topic, but I've noticed that the above invokes
the function once per output column:

CREATE FUNCTION xyz(INOUT x integer, INOUT y integer, OUT z integer) AS $$
BEGIN
    RAISE INFO 'calling xyz';
    z := x + y;
END;
$$ LANGUAGE plpgsql IMMUTABLE;

SELECT xyz(1,2);
INFO:  calling xyz
   xyz   
---------
 (1,2,3)
(1 row)

SELECT (xyz(1,2)).*;
INFO:  calling xyz
INFO:  calling xyz
INFO:  calling xyz
 x | y | z 
---+---+---
 1 | 2 | 3
(1 row)

Is that because the splat causes the query to be expanded into
"SELECT (xyz(1,2)).x, (xyz(1,2)).y, (xyz(1,2)).z"?  Is it possible
or desirable to optimize that into a single call, at least if the
function were stable or immutable?

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2005-04-29 17:34:49
Subject: Re: [GENERAL] Returning a RECORD, not SETOF RECORD
Previous:From: Marc G. FournierDate: 2005-04-29 16:34:56
Subject: Re: Feature freeze date for 8.1

pgsql-general by date

Next:From: Tom LaneDate: 2005-04-29 17:23:53
Subject: Re: Composite types as columns used in production?
Previous:From: Chris BrowneDate: 2005-04-29 16:59:14
Subject: Slowness of Big Graphical Arrays

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group