Re: RETURNS SETOF RECORD with 1 column

From: Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: RETURNS SETOF RECORD with 1 column
Date: 2017-07-27 14:20:46
Message-ID: CAHjZ2x5v6WDoYpJwxcgWaFAkjjPLrJD0DZCL4BYF3A2=ODjZMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2017-07-27 16:03 GMT+02:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

Thanks a lot for your reply with valuable details.

> Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it> writes:
>> CREATE OR REPLACE FUNCTION afun1( OUT ot TEXT )
>> RETURNS SETOF RECORD
>
>> The error message for afun1() reads:
>> ERROR: function result type must be text because of OUT parameters
>
> Indeed. It's trying to protect you from simple typos.

Which typo?
It looks it's preventing me from consistently using another simple
syntax for FRSes.

CREATE OR REPLACE FUNCTION afun1( OUT ot TEXT )
RETURNS SETOF TEXT ...

CREATE OR REPLACE FUNCTION afun2( OUT ot TEXT, OUT it INT )
RETURNS SETOF RECORD ...

CREATE OR REPLACE FUNCTION afun3( OUT ot TEXT, OUT it INT, OUT on NUMERIC )
RETURNS SETOF RECORD ...

CREATE OR REPLACE FUNCTION afun4( OUT ot TEXT, OUT it INT, OUT on
NUMERIC, OUT od DATE )
RETURNS SETOF RECORD ...

This means that RETURNS SETOF RECORD syntax is only available from 2 columns on.
While RETURNS TABLE() syntax is always available, *also* for 1 column.
I thought that "RETURNS SETOF RECORD" was meant for FRSes just like
RETURN TABLE() is.
Why not, then?

> If you want a consistent syntax I'd suggest
>
> CREATE OR REPLACE FUNCTION afun1() RETURNS TABLE (ot text) ...

Indeed.
The main difference is that with RETURNS SETOF RECORD I still get the
"usual"(tm) function argument list in the usual place: between two
parentheses.
It's a matter of style. And a consistent one.
But I still don't get the point for not having it for a single column.
Surely it's my fault.

> It's still really "setof text" under the hood.
>
> regards, tom lane

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tiffany Thang 2017-07-27 14:43:07 Re: Developer GUI tools for PostgreSQL
Previous Message Tom Lane 2017-07-27 14:03:22 Re: RETURNS SETOF RECORD with 1 column