Re: Returning a row from a function with an appended array field - Mailing list pgsql-general

From David Johnston
Subject Re: Returning a row from a function with an appended array field
Date
Msg-id 8E521C3C-5A39-49E2-BA4B-080215387A2C@yahoo.com
Whole thread Raw
In response to Returning a row from a function with an appended array field  (Wes Cravens <wcravens@cortex-it.com>)
Responses Re: Returning a row from a function with an appended array field  (Wes Cravens <wcravens@cortex-it.com>)
List pgsql-general
On Nov 9, 2011, at 20:19, Wes Cravens <wcravens@cortex-it.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.

pgsql-general by date:

Previous
From: Wes Cravens
Date:
Subject: Returning a row from a function with an appended array field
Next
From: Wes Cravens
Date:
Subject: Re: Returning a row from a function with an appended array field