public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ron Johnson <[email protected]>
To: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions
Date: Tue, 18 Jun 2024 13:07:16 -0400
Message-ID: <CANzqJaA-Bmsq5npa1qCaQkDMb-4+9ZqZVUHqpVzURJ-RtSgS-w@mail.gmail.com> (raw)
In-Reply-To: <CACX+KaPBaSW+0PyMC7dmY6W9W8mPSbWpkJRhAOQOC9Qb0TjCQA@mail.gmail.com>
References: <CACX+KaPBaSW+0PyMC7dmY6W9W8mPSbWpkJRhAOQOC9Qb0TjCQA@mail.gmail.com>
fun1 returns a table set just like any other SELECT statement.
fun2 puzzles me. Why would you return parameters AND *a single record* (unless
it's an error status).
fun3 just returns two parameters. Why isn't it a procedure?
fun2, returning parameters AND a function value, would have made my Comp
Sci professors very, very angry. Definitely Bad Practice.
You choose which to use based on how much data you want to return.
On Tue, Jun 18, 2024 at 12:50 PM Ayush Vatsa <[email protected]>
wrote:
> Hi PostgreSQL community,
> Recently I am exploring extensions in postgres and got a little confused
> regarding the function definition present in SQL file. For example consider
> below three functions:
>
> CREATE FUNCTION fun1(integer)
> RETURNS TABLE(
> col1 integer,
> col2 text
> )
> AS 'MODULE_PATHNAME', 'fun1'
> LANGUAGE C;
>
> CREATE FUNCTION fun2(
> IN input integer,
> OUT col1 integer,
> OUT col2 text
> )
> RETURNS SETOF record
> AS 'MODULE_PATHNAME', 'fun2'
> LANGUAGE C;
>
> CREATE FUNCTION fun3(
> IN input integer,
> OUT col1 integer,
> OUT col2 text
> )
> AS 'MODULE_PATHNAME', 'fun3'
> LANGUAGE C;
>
> 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.
> Whereas "fun3" is used when we are returning only one row, but my doubt
> for "fun3" is that, Can the above definition (used for fun1 and fun2) cover
> both single and multiple row scenarios.
>
> 2/ How does someone decide which type of definition is to be used?
>
> Regards
> Ayush Vatsa
>
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]
Subject: Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions
In-Reply-To: <CANzqJaA-Bmsq5npa1qCaQkDMb-4+9ZqZVUHqpVzURJ-RtSgS-w@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