A
A
Alexander Afanasiev2016-07-04 17:44:01
PostgreSQL
Alexander Afanasiev, 2016-07-04 17:44:01

How to set data type in postgresql functions?

Essence: it is necessary to make a loop in the function according to the results of SELECT. Simple option:

v versions%rowtype;
FOR v IN
    select * from versions ver where iddoc=doc_id 
LOOP
    ver_id:=COALESCE(v.id,'-1');
    ver_num:=COALESCE(v.number,'-1');
    res:= ver_id || ver_num;
END LOOP;

where versions is a table with a specific set of columns. but I need to loop on
select *, verstatus(id) from versions ver where iddoc=doc_id
where verstatus(id) is a function that displays additional information depending on id, i.e. this column is not present in versions...
it should turn out something type:
v ???(versions + other_column)%rowtype;
FOR v IN
    select *, verstatus(id) from versions ver where iddoc=doc_id 
LOOP
    ver_id:=COALESCE(v.id,'-1');
    ver_num:=COALESCE(v.number,'-1');
    ver_stat:=COALESCE(v.verstatus, '' );
    res:= ver_id || ver_num || ver_stat;
END LOOP;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2016-07-04
@XanderEVG

v record;
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question