From: Jasen Betts <jasen@xnet.co.nz>
To: pgsql-sql@postgresql.org
Subject: Re: Multiple return values and assignment
Date: 27 Apr 2009 08:48:26 GMT
Message-ID: <gt3rgq$f6m$1@reversiblemaps.ath.cx> (raw)
References: <200904251306.44880.leif@solumslekt.org>
On 2009-04-25, Leif B. Kristensen <leif@solumslekt.org> wrote:
> I've got a function that returns both an integer and a string as a
> user-defined composite type int_text:
>
> -- CREATE TYPE int_text AS (number INTEGER, string TEXT);
>
> Basically, the function does some heuristics to extract a sort order
> number from a text, and conditionally modify the text:
>
> CREATE OR REPLACE FUNCTION get_sort(INTEGER, INTEGER, TEXT)
> RETURNS int_text AS $$
...
> To use the two values in an other function where I've declared a
> variable sort_text of type int_text, I do like this:
>
> SELECT number, string FROM get_sort(par_id, srt, txt) INTO sort_text;
the above is equivalent to
sort_text = get_sort(par_id, srt, txt);
> srt := sort_text.number;
> txt := sort_text.string;
> But I feel it's a little awkward. Is there a more elegant way to do it?
SELECT * FROM get_sort(par_id, srt, txt) INTO srt,txt;
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: jasen@xnet.co.nz
Subject: Re: Multiple return values and assignment
In-Reply-To: <gt3rgq$f6m$1@reversiblemaps.ath.cx>
* 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