Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-19 Thread David G. Johnston
On Wednesday, June 19, 2024, Ayush Vatsa wrote: > Hi David, > Thanks for clarification > > I prefer TABLE. Using setof is more useful when the returned type is > predefined > But in the table also isn't the returned type predefined? Example: > CREATE FUNCTION fun1(integer) > RETURNS TABLE( >

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-19 Thread Ayush Vatsa
Hi David, Thanks for clarification > I prefer TABLE. Using setof is more useful when the returned type is predefined But in the table also isn't the returned type predefined? Example: CREATE FUNCTION fun1(integer) RETURNS TABLE( col1 integer, col2 text ) AS 'MODULE_PATHNAME', 'fun1

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread Tom Lane
"David G. Johnston" writes: > On Tuesday, June 18, 2024, Ron Johnson wrote: >> What's the purpose? Legacy of not having procedures? > So people can have a style guide that says always specify a returns clause > on function definitions. To my mind, the reason we allow RETURNS together with OUT

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread David G. Johnston
On Tuesday, June 18, 2024, Ron Johnson wrote: > On Tue, Jun 18, 2024 at 2:37 PM David G. Johnston < > david.g.johns...@gmail.com> wrote: > >> On Tuesday, June 18, 2024, Ron Johnson wrote: >> >>> On Tue, Jun 18, 2024 at 1:57 PM David G. Johnston < >>> david.g.johns...@gmail.com> wrote: >>> O

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread Ron Johnson
On Tue, Jun 18, 2024 at 2:37 PM David G. Johnston < david.g.johns...@gmail.com> wrote: > On Tuesday, June 18, 2024, Ron Johnson wrote: > >> On Tue, Jun 18, 2024 at 1:57 PM David G. Johnston < >> david.g.johns...@gmail.com> wrote: >> >>> On Tuesday, June 18, 2024, Ron Johnson wrote: >>>

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread David G. Johnston
On Tuesday, June 18, 2024, Ron Johnson wrote: > On Tue, Jun 18, 2024 at 1:57 PM David G. Johnston < > david.g.johns...@gmail.com> wrote: > >> On Tuesday, June 18, 2024, Ron Johnson wrote: >> >>> >>> But I stand by returning OUT params and records at the same time. >>> >> >> You mean you dislike

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread Ron Johnson
On Tue, Jun 18, 2024 at 1:57 PM David G. Johnston < david.g.johns...@gmail.com> wrote: > On Tuesday, June 18, 2024, Ron Johnson wrote: > >> >> But I stand by returning OUT params and records at the same time. >> > > You mean you dislike adding the optional returns clause when output > parameters

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread David G. Johnston
On Tuesday, June 18, 2024, Ron Johnson wrote: > > But I stand by returning OUT params and records at the same time. > You mean you dislike adding the optional returns clause when output parameters exist? Because the out parameters and the “record” represent the exact same thing. David J.

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread Ron Johnson
On Tue, Jun 18, 2024 at 1:16 PM David G. Johnston < david.g.johns...@gmail.com> wrote: > On Tue, Jun 18, 2024 at 10:07 AM Ron Johnson > wrote: > >> fun2 puzzles me. Why would you return parameters AND *a single record* >> (unless >> it's an error status). >> > > You mis-understand what 2 is doi

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread David G. Johnston
On Tue, Jun 18, 2024 at 10:07 AM Ron Johnson wrote: > fun2 puzzles me. Why would you return parameters AND *a single record* > (unless > it's an error status). > You mis-understand what 2 is doing. You should go re-read the docs for create function again. Especially the description of rettyp

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread David G. Johnston
On Tue, Jun 18, 2024 at 9:50 AM Ayush Vatsa 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 definiti

Re: Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread Ron Johnson
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 Com

Seeking Clarification on Function Definitions in PostgreSQL Extensions

2024-06-18 Thread Ayush Vatsa
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_PAT