From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Vibhor Kumar <vibhor(dot)kumar(at)enterprisedb(dot)com> |
Cc: | Jon Smark <jon(dot)smark(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Passing a table as parameter |
Date: | 2011-03-21 20:02:43 |
Message-ID: | AANLkTi=rJ2ozyh0yv8A__2LJ=DSRet+gMudE=3ZZdrjJ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2011/3/21 Vibhor Kumar <vibhor(dot)kumar(at)enterprisedb(dot)com>:
>
> On Mar 21, 2011, at 11:13 PM, Jon Smark wrote:
>
>>
>> Is there any way for a SQL or PL/pgSQL function to receive a table
>> as parameter? As an illustration, consider the dummy example below.
>> Note that functions get_from_data1 and get_from_data2 follow essentially
>> the same pattern; it would be nice to define instead a single polymorphic
>> function parameterised on the id and table. Is this possible?
>
>
> Try Something like given below:
> CREATE OR REPLACE FUNCTION tab_pass(text) returns setof numeric
> as
> $$
> DECLARE
> rec record;
> BEGIN
> for rec in execute 'select empno from '||$1||' where id = 1'
> LOOP
> return next rec.empno;
> END LOOP;
> return next rec.empno;
> END;
> $$ language plpgsql;
it can work too, but there is sql injection risk.
Do newer 'SELECT ... FROM ' || tabname || ' ...
Regards
Pavel Stehule
>
>
> Thanks & Regards,
> Vibhor Kumar
> EnterpriseDB Corporation
> The Enterprise PostgreSQL Company
> vibhor(dot)kumar(at)enterprisedb(dot)com
> Blog:http://vibhork.blogspot.com
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
From | Date | Subject | |
---|---|---|---|
Next Message | Aljoša Mohorović | 2011-03-21 20:09:35 | Re: postgres conferences missing videos? |
Previous Message | Alex | 2011-03-21 19:54:52 | postgresql install problem |