RETURNS SETOF RECORD with 1 column

From: Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: RETURNS SETOF RECORD with 1 column
Date: 2017-07-27 11:27:58
Message-ID: CAHjZ2x7eOnb2vMQ=eFh=jUTqLar7uwY=hk7M_WWF6-yXmJVaLQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all.

Please, see this fragment:

DROP TABLE IF EXISTS atable;
CREATE TABLE atable (
atext TEXT,
anint INT
);

TRUNCATE atable;
INSERT INTO atable VALUES
( 'one',1 ),
( 'two',2 ),
( 'three',3 ),
( 'four',4 )
;

CREATE OR REPLACE FUNCTION afun1( OUT ot TEXT )
RETURNS SETOF RECORD
LANGUAGE PLPGSQL
AS $l0$
BEGIN
RETURN QUERY SELECT atext FROM atable;
END;
$l0$;

CREATE OR REPLACE FUNCTION afun2( OUT ot TEXT, OUT oi INT )
RETURNS SETOF RECORD
LANGUAGE PLPGSQL
AS $l0$
BEGIN
RETURN QUERY SELECT atext,anint FROM atable;
END;
$l0$;

I am not allowed to create afun1() but can create and use afun2().
The error message for afun1() reads:

ERROR: function result type must be text because of OUT parameters

The idea I understand is that a RECORD must have no less than TWO columns.
Of course it's not a problem to declare "RETURNS SETOF TEXT", but why
forcing me to "deviate" from a very general construct for a 1 column
case?

Is this a bug/enhancement or am I missing something?

TALIA!

--
Vincenzo Romano - NotOrAnd.IT
Information Technologies
--
NON QVIETIS MARIBVS NAVTA PERITVS

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2017-07-27 12:58:35 Re: Interesting streaming replication issue
Previous Message Daniele Varrazzo 2017-07-27 11:20:51 upsert: is there a shortcut?