Declaring a field that is also an out parameter in a function - Mailing list pgsql-general

From Michael Nolan
Subject Declaring a field that is also an out parameter in a function
Date
Msg-id CAOzAquKPXRWp38u9cURDCd4XzKCbKLhuZvH6AQjtXGW3R6-LoQ@mail.gmail.com
Whole thread Raw
Responses Re: Declaring a field that is also an out parameter in a function
List pgsql-general
In the following short code, the out parameter d3 is also declared, so
its value will be null in the output.

create or replace function public.test_function(in varchar, in char, in date, ou
t d1 text, out d2 integer, out d3 char, out d4 date )
stable as $$

DECLARE

   wk_intxt alias for $1;
   wk_inchar  alias for $2;
   wk_indate alias for $3;
   d3 char;

BEGIN

   d1 := 'foo,bar';
   d2 := 15;
   d3 := 'X';
   d4 := current_date;

END

$$ language 'plpgsql';

Here's what happens in 16.1:

psql (16.1)
Type "help" for help.

uscf=> select test_function('1234','a','2024-01-01')
uscf-> \g
       test_function
----------------------------
 ("foo,bar",15,,2024-07-06)
(1 row)

Shouldn't declaring a field that is also an OUT parameter throw an error?

Mike Nolan
htfoot@gmail.com



pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Load a csv or a avro?
Next
From: Tom Lane
Date:
Subject: Re: Declaring a field that is also an out parameter in a function