Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions
Дата
Msg-id CAKFQuwbtbhkbw439S3_UbraTpyHfQGxdjjhBBUbfKPd4PVC+xg@mail.gmail.com
обсуждение исходный текст
Ответ на Seeking Clarification on Function Definitions in PostgreSQL Extensions  (Ayush Vatsa <ayushvatsa1810@gmail.com>)
Ответы Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions
Список pgsql-general
On Tue, Jun 18, 2024 at 9:50 AM Ayush Vatsa <ayushvatsa1810@gmail.com> wrote:
1/ I wanted to know what's the difference between the above three definitions.
As per my understanding, "fun1" and "fun2" look the same, taking one integer and returning two columns with multiple rows.

Yes.
 

Can the above definition (used for fun1 and fun2) cover both single and multiple row scenarios.

In so far as one is a valid number of rows to return from a function that returns zero or more rows, yes.  But if the function is incapable of returning more than one result it should not be marked with table/setof on semantic grounds.


2/ How does someone decide which type of definition is to be used?


Between 1 and 2 is a style choice.  I prefer TABLE.  Using setof is more useful when the returned type is predefined.  Or a true record where the caller has to specify the shape.

For 3, having a non-set-returning-function that outputs multiple columns is just odd, IMO.  Personally I'd go for pre-defining a composite type, then return that type.

David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: Ron Johnson
Дата:
Сообщение: Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions