Re: Returning a row from a function with an appended array field

From: David Johnston <polobo(at)yahoo(dot)com>
To: Wes Cravens <wcravens(at)cortex-it(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Returning a row from a function with an appended array field
Date: 2011-11-10 01:34:12
Message-ID: 8E521C3C-5A39-49E2-BA4B-080215387A2C@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Nov 9, 2011, at 20:19, Wes Cravens <wcravens(at)cortex-it(dot)com> wrote:

> 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
>

Use "WITH RECURSIVE" instead of a function.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Morton 2011-11-10 01:43:27 PG 9.0.5 RPM's for SLES - Where to get !?
Previous Message Wes Cravens 2011-11-10 01:19:59 Returning a row from a function with an appended array field