Re: BUG #5154: ERROR: cannot assign non-composite value to a row variable

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: Jeff Shanab <jshanab(at)earthlink(dot)net>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5154: ERROR: cannot assign non-composite value to a row variable
Date: 2009-11-01 06:54:43
Message-ID: 162867790910312354v6473aba4i81e35323c4671746@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

2009/11/1 Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>:
>>>>>> "Pavel" == Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
>
>  >> As discussed on the irc. I had a problem with a utility function
>  >> that was being passed a NEW row and a null for the OLD row. The
>  >> error was created when it tries to store the row variable in the
>  >> local variables. RhodiumToad on the list provided this simple
>  >> test.
>  >>
>  >> create type foo1 as (a integer, b text);
>  >> CREATE TYPE
>  >> create type foo2 as (c integer, d foo1);
>  >> CREATE TYPE
>  >>
>  >> create function foo() returns foo2 language plpgsql as $f$ declare v foo2;
>  >> begin v := null; return v; end; $f$;
>  >> CREATE FUNCTION
>
>  Pavel> This isn't bug - it is just feature.
>
> No, it's a bug.
>
> Here's a clearer testcase:
>
> create type foo1 as (a integer, b text);
> create type foo2 as (c integer, d foo1);
>
> create or replace function foo1() returns foo1 language plpgsql
>  as $f$ declare v foo1; begin v := null::foo1; return v; end; $f$;
>
> create or replace function foo2() returns foo2 language plpgsql
>  as $f$ declare v foo2; begin v := null::foo2; return v; end; $f$;
>
> select foo1();
>  foo1
> ------
>  (,)
> (1 row)
>
> select foo2();
> ERROR:  cannot assign non-composite value to a row variable
> CONTEXT:  PL/pgSQL function "foo2" line 1 at assignment
>
> Alternatively:
>
> create or replace function foo1(r foo1) returns foo1 language plpgsql
>  as $f$ declare v foo1; begin v := r; return v; end; $f$;
> create or replace function foo2(r foo2) returns foo2 language plpgsql
>  as $f$ declare v foo2; begin v := r; return v; end; $f$;
>
> select foo1(null);
>  foo1
> ------
>  (,)
> (1 row)
>
> select foo2(null);
> ERROR:  cannot assign non-composite value to a row variable
> CONTEXT:  PL/pgSQL function "foo2" while storing call arguments into local variables
>
> These calls should either both work or both fail.
>

ok - it is bug. PL/pgSQL doesn't assign values well over nested
composite types. I am not sure, maybe this behave isn't limited by
NULL value.

Regards
Pavel Stehule

> --
> Andrew (irc:RhodiumToad)
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Mark Kirkwood 2009-11-01 07:12:27 Re: BUG #5150: math bug
Previous Message Craig Ringer 2009-11-01 06:31:56 Re: BUG #5149: Can't untar the src code file