Re: RETURNS SETOF RECORD with 1 column

From: Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: RETURNS SETOF RECORD with 1 column
Date: 2017-07-28 07:43:35
Message-ID: CAHjZ2x7ZZe9=6CpfU1sK7zFuahy+9C+69s5zP_TmPsU=WN=0cw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2017-07-28 8:36 GMT+02:00 David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>:
> On Thursday, July 27, 2017, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
> wrote:
>>
>> On Thursday, July 27, 2017, Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>
>> wrote:
>>>
>>> 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.
>>>
>>
>> Docs say: " When there are OUT or INOUT parameters, the RETURNS clause can
>> be omitted. ". Sounds like you should you do just that.
>>
>
> Except you'd have no where to put the "setof" modifier...So, yeah, you
> probably aren't going to personal style preference catered to here.
>
> David J.

Thanks David.

I have found the actual documentation of the inconsistent syntax.

It's here
https://www.postgresql.org/docs/9.6/static/sql-createfunction.html
at the description for the parameter "rettype":

[QUOTE]
When there are OUT or INOUT parameters, the RETURNS clause can be omitted.
If present, it must agree with the result type implied by the output parameters:
RECORD if there are **multiple output parameters**, or the same type
as the single output parameter.
The SETOF modifier indicates that the function will return a set of
items, rather than a single item.
The type of a column is referenced by writing table_name.column_name%TYPE.
[/QUOTE]

That single predicate, "multiple output parameters", is creating the
(useless?) special case for a single column output.
I would like to understand the typo protection mentioned by Tom earlier:
I need to understand the reason for creating that special case.

--
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 Tim Uckun 2017-07-28 09:28:03 Re: Developer GUI tools for PostgreSQL
Previous Message vinny 2017-07-28 06:53:51 Re: Developer GUI tools for PostgreSQL