Recursive function that receives a list of IDs and returns all child IDs

From: "Sven Haag" <sven-haag(at)gmx(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Recursive function that receives a list of IDs and returns all child IDs
Date: 2011-03-23 15:29:08
Message-ID: 20110323152908.304810@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hello pgsql fans out there,

i've already created a function that returns a list of IDs of all sub-samples based on a given sample ID. this works fine. now i like to extend this function so that it can receive a list of sample IDs. e.g.:

fn_get_subsamples(IN sample_numbers SETOF integer)

here is the existing function:

CREATE OR REPLACE FUNCTION fn_get_subsamples(IN sample_number integer)
RETURNS SETOF integer AS
$BODY$
WITH RECURSIVE recursetree(sample_number) AS (
SELECT sample_number
FROM sample
WHERE parent_sample = $1

UNION ALL

SELECT t.sample_number
FROM sample t
JOIN recursetree rt ON rt.sample_number = t.parent_sample
)

SELECT sample_number
FROM recursetree;
$BODY$
LANGUAGE sql VOLATILE

thanks a lot for every hint!
sven
--
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Schreyer 2011-03-23 15:32:58 Re: Weird problems with C extension and bytea as input type
Previous Message David Johnston 2011-03-23 15:08:34 Re: General question