Thread: Problem with PlPgsql function on composite types

Problem with PlPgsql function on composite types

From
tolik@icomm.ru (Anatoly K. Lasareff)
Date:
Hi, all!

I use postgres 6.4 under FreeBSD.

I create table 'a':

Table    = a
+----------------------------------+----------------------------------+-------+
|              Field               |              Type                | Length|
+----------------------------------+----------------------------------+-------+
| dt                               | datetime                         |     8 |
| i                                | int4                             |     4 |
+----------------------------------+----------------------------------+-------+

with some values:

tolik=> select * from a;
dt                          |i
----------------------------+-
Thu Nov 26 16:35:23 1998 MSK|1
Wed Nov 25 00:00:00 1998 MSK|2
Fri Nov 27 00:00:00 1998 MSK|3
(3 rows)


Then I create simple function:

--------------------------------------
create function fff(a) returns a as
'
declare
  inp    alias for $1;
begin
  raise notice ''i=% dt=%'', inp.i, inp.dt;
  return inp;
end;
'
language 'plpgsql';
--------------------------------------

This function returns its input argument without changing and notice
values of input row. When I execute statement

select dt(fff(a));

I get follow output:
-----------------------------------------------

NOTICE:  i=1 dt=Thu Nov 26 16:35:23 1998 MSK
NOTICE:  i=<NULL> dt=<NULL>
NOTICE:  i=2 dt=Wed Nov 25 00:00:00 1998 MSK
NOTICE:  i=<NULL> dt=<NULL>
NOTICE:  i=3 dt=Fri Nov 27 00:00:00 1998 MSK
NOTICE:  i=<NULL> dt=<NULL>
dt
----------------------------
Sat Jan 01 03:00:00 2000 MSK
Sat Jan 01 03:00:00 2000 MSK
Sat Jan 01 03:00:00 2000 MSK
(3 rows)
-----------------------------------------------

My questions are:

1) why the function calls 6 times, but not 3 times

2) what the data are in this output

3) how can I right write function, working with composite types?

Help me, please...

--
Anatoly K. Lasareff              Email:       tolik@icomm.ru