From: | Sven Haag <sven-haag(at)gmx(dot)de> |
---|---|
To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Recursive function that receives a list of IDs and returns all child IDs |
Date: | 2011-03-24 21:49:22 |
Message-ID: | 4D8BBC62.8080009@gmx.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
thanks a lot!
that function does it exactly as wished ;)!
Am 23.03.2011 22:46, schrieb Merlin Moncure:
> On Wed, Mar 23, 2011 at 10:29 AM, Sven Haag<sven-haag(at)gmx(dot)de> wrote:
>> 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
>
> CREATE OR REPLACE FUNCTION fn_get_subsamples(IN sample_numbers integer[])
> RETURNS SETOF integer AS
> $BODY$
> WITH RECURSIVE recursetree(sample_number) AS (
> SELECT sample_number
> FROM sample
> WHERE parent_sample in (select unnest($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
>
> merlin
>
From | Date | Subject | |
---|---|---|---|
Next Message | David Johnston | 2011-03-24 22:17:18 | Re: Default permissions for CREATE SCHEMA/TABLE? |
Previous Message | Adrian Klaver | 2011-03-24 21:00:02 | Re: Default permissions for CREATE SCHEMA/TABLE? |