简体   繁体   中英

PostgreSQL: Accessing data of RECORD type in a plpgsql function

This is my first function:

CREATE  FUNCTION func1(INOUT a  integer,OUT b integer,  OUT c float, OUT   d integer,OUT e decimal)
 AS  $BODY$
DECLARE

BEGIN
.
.
.   
END
$BODY$
LANGUAGE plpgsql VOLATILE

Output is:

$ SELECT * FROM func1(242);

a | b | c | d | e
--+--+--+--+---

242 | 5 | 7.5 | 15 | 1.2208

And this is second function:

CREATE  FUNCTION func2()
   AS  $BODY$
DECLARE
   d  RECORD;

BEGIN
    EXECUTE 'SELECT * FROM func1(242)' INTO d;  
    raise notice 'arr: %', d;.  -– output is->  NOTICE:  arr: (242,5,7.5,15,1.2208)
--HERE I want access to a,b,....
    .
    .   
END
$BODY$
LANGUAGE plpgsql VOLATILE

How I can access separately to a,b,c,d and e variables inside func2.

Here's one solution:

FOR d in EXECUTE 'SELECT * FROM func1(242)'
LOOP
  --here you can access them, or assign them to a local variable
  raise notice 'a:%, b:%, c:%, d:%, e:%', d.a, d.b, d.c, d.d, d.d, d.e;
END LOOP;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM