Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id E53C7632B67 for ; Mon, 27 Apr 2009 05:48:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 53420-04 for ; Mon, 27 Apr 2009 05:48:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from oberon.wxnz.net (oberon.wxnz.net [58.28.6.13]) by mail.postgresql.org (Postfix) with ESMTP id 6EC5D632874 for ; Mon, 27 Apr 2009 05:48:58 -0300 (ADT) Received: from gonzo (ip-118-90-140-242.xdsl.xnet.co.nz [118.90.140.242]) by oberon.wxnz.net (Postfix) with ESMTP id D8D2346419B for ; Mon, 27 Apr 2009 20:48:54 +1200 (NZST) Received: from news by gonzo with local (Exim 4.69) (envelope-from ) id 1LyMVw-00043E-Tr for pgsql-sql@postgresql.org; Mon, 27 Apr 2009 20:48:36 +1200 To: pgsql-sql@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.sql Subject: Re: Multiple return values and assignment Date: 27 Apr 2009 08:48:26 GMT Organization: Dis (not Dat) Organisation Lines: 31 Message-ID: References: <200904251306.44880.leif@solumslekt.org> NNTP-Posting-Host: localhost Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reversiblemaps.ath.cx 1240822106 15574 127.0.0.1 (27 Apr 2009 08:48:26 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-2 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200904/121 X-Sequence-Number: 32467 On 2009-04-25, Leif B. Kristensen 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;