public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[email protected]>
To: Ayush Vatsa <[email protected]>
Cc: [email protected]
Subject: Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions
Date: Tue, 18 Jun 2024 10:13:08 -0700
Message-ID: <CAKFQuwbtbhkbw439S3_UbraTpyHfQGxdjjhBBUbfKPd4PVC+xg@mail.gmail.com> (raw)
In-Reply-To: <CACX+KaPBaSW+0PyMC7dmY6W9W8mPSbWpkJRhAOQOC9Qb0TjCQA@mail.gmail.com>
References: <CACX+KaPBaSW+0PyMC7dmY6W9W8mPSbWpkJRhAOQOC9Qb0TjCQA@mail.gmail.com>

On Tue, Jun 18, 2024 at 9:50 AM Ayush Vatsa <[email protected]>
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.


view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions
  In-Reply-To: <CAKFQuwbtbhkbw439S3_UbraTpyHfQGxdjjhBBUbfKPd4PVC+xg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox