Returning a row from a function with an appended array field

From: Wes Cravens <wcravens(at)cortex-it(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Returning a row from a function with an appended array field
Date: 2011-11-10 01:19:59
Message-ID: 4EBB26BF.5090906@cortex-it.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have an adjacency list kind of table

CREATE TABLE thingy (
id int,
parent int
);

I'd like to be able to write a procedural function that returns a row or
rows from this table with an appended field that represents the children.

Something like this pseudo code:

FOR row IN SELECT * FROM thingy
LOOP
RETURN NEXT row,[SELECT id FROM thingy WHERE parent_id = id]
END LOOP,
RETURN

Any help much appreciated,

Wes

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-11-10 01:34:12 Re: Returning a row from a function with an appended array field
Previous Message David Johnston 2011-11-10 00:42:53 Re: PostgreSQL 9.0.5 concat Issue