writing functions with return type record

From: Roberto Bellandi <roberto(at)b2tel(dot)it>
To: pgsql-www(at)postgresql(dot)org
Subject: writing functions with return type record
Date: 2017-02-14 15:24:06
Message-ID: 58A32116.1060307@b2tel.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-www

Hi, i'am try to encapsulate some logic into funtions to clear design,

my question is:

CREATE OR REPLACE FUNCTION get_something(various param)
RETURNS SETOF mydummytable AS
$BODY$
DECLARE
v_rec mydummytable%rowtype;
BEGIN
FOR v_rec IN (select field1, field2 blabla)
LOOP
RETURN NEXT v_rec;
END LOOP;
RETURN;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;

with mydummytable a real empty table
i can use function in query like this

select field1 from get_something(...)

without creation of table mydummytable and use in function type RECORD

i can use
select field1 from get_something(...)a (field1 type, field2 type,...)

is possible and if yes how to write function return rowset or where
store mydummytable structure without create table mydummytable
and use function in query like this select field1 from
get_something(...) without a (field1 type, field2 type,...) definition

PS i read about resultset fully retrieve , my query in function at
maximum return one or two row

Responses

Browse pgsql-www by date

  From Date Subject
Next Message Justin Clift 2017-02-14 15:53:57 Re: writing functions with return type record
Previous Message Aleksander Alekseev 2017-02-13 14:54:30 Re: Wiki editor request