Re: Pipelined functions in Postgres
- From: "Milen Kulev" <makulev(at)gmx(dot)net>
- To: "'Talha Khan'" <talha(dot)amjad(at)gmail(dot)com>
- Cc: <pgsql-performance(at)postgresql(dot)org>
- Subject: Re: Pipelined functions in Postgres
- Date: Tue, 19 Sep 2006 23:29:07 +0200
- Message-id: <008b01c6dc32$a35c5290$0a00a8c0(at)trivadis(dot)com>
Title: Nachricht
Talha,
do you
know how much memory is consumed by the SETOF function
?
What
happens with memory consumption of the function if
SELECT
ename FROM emp WHERE sal > $1
returns 10 mio
rows ?
I suppose
that memory for the RECORD structure is immediately reused by the
next record.
Regards,
Milen
Hi Milen,
Pipelined function is a code that acts like a database table.
Inorder to use this functionality in postgres you would need to write the
function like this
CREATE OR REPLACE FUNCTION get_test_data (numeric)
RETURNS SETOF RECORD AS
$$
DECLARE
temp_rec
RECORD;
BEGIN
FOR temp_rec IN (SELECT ename FROM
emp WHERE sal > $1)
LOOP
RETURN NEXT temp_rec;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
now inorder to call this function you would write the code as
follows
SELECT * FROM get_test_data(1000) AS t1 (emp_name
VARCHAR);
Regards
Talha Amjad
Home |
Main Index |
Thread Index