Can I do something like this:
CREATE TABLE sample (id SERIAL, node INTEGER, parent INTEGER);
INSERT INTO sample(node,parent) VALUES(1,0);
INSERT INTO sample(node,parent) VALUES(2,0);
INSERT INTO sample(node,parent) VALUES(3,1);
INSERT INTO sample(node,parent) VALUES(4,3)
CREATE OR REPLACE FUNCTION article_display(anyelement, anyelement)
RETURNS SETOF samle AS $$
DECLARE
articleRow sample%ROWTYPE;
BEGIN
FOR articleRow IN SELECT comments
FROM theirry.articles
ORDER BY article_id
DESC LIMIT $1
OFFSET $2 LOOP
RETURN NEXT articleRow;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
Thanks,
J