Xiujiao Gao
Xiujiao Gao

Reputation: 99

a column definition list is required for functions returning "record"

CREATE OR REPLACE FUNCTION transformServers(data jsonb)
RETURNS SETOF record  as $$                        
DECLARE                                            
r record;                                          

BEGIN                                              
for r in select.serversSet.id,serversSet.hostname from jsonb_to_recordset(data->'data') AS           
 serversSet (                                       
 id bigint,                                         
 hostname text,                                                                                                                                  
) loop                                             
return next r;                                     
end loop;                                          
return;  
 END;
 $$ language plpgsql;

I run the above code, got an error saying " a column definition list is required for functions returning "record"

Upvotes: 3

Views: 7699

Answers (1)

Xiujiao Gao
Xiujiao Gao

Reputation: 99

Problem solved! Actually the problem is in another function, where I call transformServers(json).

Each time we call a function which returns setof record, we need to specify the columns, so when we call transformServers(json) we have to do it as

 select * from transformServers(json) as f(id bigint, hostname text) 

Before, I did

 select * from transformServers(json)

which does not work.

Upvotes: 7

Related Questions