Declaring a field that is also an out parameter in a function

From: Michael Nolan <htfoot(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Declaring a field that is also an out parameter in a function
Date: 2024-07-06 21:29:12
Message-ID: CAOzAquKPXRWp38u9cURDCd4XzKCbKLhuZvH6AQjtXGW3R6-LoQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-07-06 22:13:49 Re: Declaring a field that is also an out parameter in a function
Previous Message Ron Johnson 2024-07-06 20:23:17 Re: Load a csv or a avro?