pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type.
3+ messages / 3 participants
[nested] [flat]

* BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type.
@ 2018-06-18 22:32 PG Bug reporting form <noreply@postgresql.org>
  2018-06-18 22:41 ` Re: BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type. David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2018-06-18 22:32 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: anderson.ant.oli@gmail.com

The following bug has been logged on the website:

Bug reference:      15246
Logged by:          Anderson Antunes
Email address:      anderson.ant.oli@gmail.com
PostgreSQL version: 10.0
Operating system:   Windows
Description:        

I'm trying to assign a popular values to a custom data type that comes from
an INOUT parameter in the function. I already searched the internet and I
did not find a solution. This type of assignment is common in Oracle. I do
not understand why it was not implemented. I get the following message:
"ERROR:" Parameter XXX "is not variable unknown".

Thank you if you can answer me.

create table my_table1
(
	co_1 integer,
	co_2 character varying(20)
);

create table my_table2
(
	co_1 char,
	co_2 double precision
);

create type my_type as
(
	rc_tb1 my_table1,
	rc_tb2 my_table2
);

create or replace function fc_test
(
	inout p_my_type my_type
)
as
$$
begin
	p_my_type.rc_tbl1.co_1 := 1; -- ERRO:  "p_my_type.rc_tbl1.co_1" is not
variable unknown !!!!
	p_my_type.rc_tbl1.co_2 := 'Teeeeeeeeeest';
	p_my_type.rc_tbl2.co_3 := 'T';
	p_my_type.rc_tbl2.co_4 := 10.56;
end;
$$
language plpgsql;



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type.
  2018-06-18 22:32 BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type. PG Bug reporting form <noreply@postgresql.org>
@ 2018-06-18 22:41 ` David G. Johnston <david.g.johnston@gmail.com>
  2018-06-19 03:06   ` Re: BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: David G. Johnston @ 2018-06-18 22:41 UTC (permalink / raw)
  To: anderson.ant.oli@gmail.com; pgsql-bugs@lists.postgresql.org

On Mon, Jun 18, 2018 at 3:32 PM, PG Bug reporting form <
noreply@postgresql.org> wrote:

>
> begin
>         p_my_type.rc_tbl1.co_1 := 1; -- ERRO:  "p_my_type.rc_tbl1.co_1" is
> not
> variable unknown !!!!
>         p_my_type.rc_tbl1.co_2 := 'Teeeeeeeeeest';
>         p_my_type.rc_tbl2.co_3 := 'T';
>         p_my_type.rc_tbl2.co_4 := 10.56;
> end;
>

​
Short answer is that you cannot simply assign components of a composite
type one-at-a-time, you have to build up the full final composite result in
one expression and assign the result of the expression to the typed
variable (p_my_type in this instance).​

​This works:

p_my_type := ROW(ROW(1, 'Teeeeeeeeeeest'), ROW('T', 10.56));

and execute:

​select * FROM fc_test(null)

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type.
  2018-06-18 22:32 BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type. PG Bug reporting form <noreply@postgresql.org>
  2018-06-18 22:41 ` Re: BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type. David G. Johnston <david.g.johnston@gmail.com>
@ 2018-06-19 03:06   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2018-06-19 03:06 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: anderson.ant.oli@gmail.com; pgsql-bugs@lists.postgresql.org

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Mon, Jun 18, 2018 at 3:32 PM, PG Bug reporting form <
> noreply@postgresql.org> wrote:
>> p_my_type.rc_tbl1.co_1 := 1; -- ERRO:  "p_my_type.rc_tbl1.co_1" is
>> not
>> variable unknown !!!!

> Short answer is that you cannot simply assign components of a composite
> type one-at-a-time, you have to build up the full final composite result in
> one expression and assign the result of the expression to the typed
> variable (p_my_type in this instance).​

It's not quite that bad.  IIRC, plpgsql handles only one level of field
assignment, so you could write

	p_my_type.rc_tbl1 := ROW(1, 'Teeeeeeeeeeest');

but not

	p_my_type.rc_tbl1.co_1 := 1;

Improving that --- and also allowing mixed array-element-and-field
assignment, say "p_my_type.rc_tbl1[2].co_1 := 1;" --- has been on the
radar screen for a long time, but nobody has gotten round to it.

I think I might've made it a bit easier as of v11, because it'd no longer
be necessary to implement field assignment in two separate code paths
for "rows" and "records".  But it's still a fair amount of work.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-06-19 03:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-18 22:32 BUG #15246: Does not allow an INOUT parameter to receive values when its data type is a user-defined data type. PG Bug reporting form <noreply@postgresql.org>
2018-06-18 22:41 ` David G. Johnston <david.g.johnston@gmail.com>
2018-06-19 03:06   ` Tom Lane <tgl@sss.pgh.pa.us>

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