Обсуждение: variadic function, query "in", help with syntax/function

Поиск
Список
Период
Сортировка

variadic function, query "in", help with syntax/function

От
Scott Ribe
Дата:
Briefly, what would it take to make the following work?

create function getbatch (variadic ids int8[]) returns setof foobar as $$
begin
    return query
        select * from foobar where id in (ids);
end;
$$ language plpgsql;

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice






Re: variadic function, query "in", help with syntax/function

От
Pavel Stehule
Дата:
Hello

2012/10/21 Scott Ribe <scott_ribe@elevated-dev.com>:
> Briefly, what would it take to make the following work?
>
> create function getbatch (variadic ids int8[]) returns setof foobar as $$
> begin
>         return query
>                 select * from foobar where id in (ids);
> end;
> $$ language plpgsql;
>

create function getbatch (variadic ids int8[]) returns setof foobar as $$
begin
        return query
                select * from foobar where id = any (ids);
end;
$$ language plpgsql;

note, for these single statement function, sql language is better

regards

Pavel Stehule


> --
> Scott Ribe
> scott_ribe@elevated-dev.com
> http://www.elevated-dev.com/
> (303) 722-0567 voice
>
>
>
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general


Re: variadic function, query "in", help with syntax/function

От
Scott Ribe
Дата:
On Oct 21, 2012, at 11:01 AM, Pavel Stehule wrote:

> Hello
>
> 2012/10/21 Scott Ribe <scott_ribe@elevated-dev.com>:
>> Briefly, what would it take to make the following work?
>>
>> create function getbatch (variadic ids int8[]) returns setof foobar as $$
>> begin
>>        return query
>>                select * from foobar where id in (ids);
>> end;
>> $$ language plpgsql;
>>
>
> create function getbatch (variadic ids int8[]) returns setof foobar as $$
> begin
>        return query
>                select * from foobar where id = any (ids);
> end;
> $$ language plpgsql;

Ah, thanks, I didn't know any worked in that context--I've just used it (and only seen examples) the other way:
const_id= any(somecol). 

> note, for these single statement function, sql language is better

I greatly simplified it for the question; it's kind of a nasty function that's multiple unions of multiple joins.

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice