pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: KÖPFERL Robert <robert.koepferl@sonorys.at>
Cc: pgsql-sql@postgresql.org
Subject: Re: returning a record from PL/pgSQL
Date: Sun, 23 Jan 2005 12:00:25 -0700
Message-ID: <20050123190024.GA18329@winnie.fuhr.org> (raw)
In-Reply-To: <ED4E30DD9C43D5118DFB00508BBBA76EB1657C@neptun.sonorys.at>
References: <ED4E30DD9C43D5118DFB00508BBBA76EB1657C@neptun.sonorys.at>

On Fri, Jan 21, 2005 at 12:41:09PM +0100, KÖPFERL Robert wrote:
>
> I just tried hard to return
> a single record fromout a plpgsql-function. While the (otherwise excelent)
> documentation didn't give me an answer, I found out that this works:
> 
>         select into ret false, balance, balance;
>         return ret;
> 
> while ret is a composite type.
>
> This construction however tastes not good to me. Is there a nicer way?

In the "Declarations" section of the PL/pgSQL documentation, under
"Row Types," is the following:

    The individual fields of the row value are accessed using the
    usual dot notation, for example rowvar.field.

and under "RETURN" in the "Control Structures" section is this:

    To return a composite (row) value, you must write a record or
    row variable as the expression.

So you could to the following:

    ret.field1 := value1;
    ret.field2 := value2;
    ret.field3 := value3;
    RETURN ret;

Internally, however, each expression in the above assignments would
be evaluated using a SELECT statement, so whether this code is
"nicer" than what you wrote depends on what you mean by "nice."

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



view thread (2+ messages)

Message-ID: <20050123190024.GA18329@winnie.fuhr.org>
Permalink:  ../20050123190024.GA18329@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050123190024.GA18329@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mike@fuhr.org, robert.koepferl@sonorys.at
  Subject: Re: returning a record from PL/pgSQL
  In-Reply-To: <20050123190024.GA18329@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox