Re: Create view is not accepting the parameter in postgres functions

Поиск
Список
Период
Сортировка
Искать
От
Merlin Moncure
Тема
Re: Create view is not accepting the parameter in postgres functions
Дата
Msg-id
CAHyXU0y=2AVPb0ThOJ644gLLe8Cz89gAS8KfWunS4kigXW7tpg@mail.gmail.com
Ответ на
Список
Дерево обсуждения
Create view is not accepting the parameter in postgres functions "Divyaprakash Y" <divyaprakash.y@celstream.com>
Re: Create view is not accepting the parameter in postgres functions Alban Hertroys <haramrae@gmail.com>
Re: Create view is not accepting the parameter in postgres functions Craig Ringer <ringerc@ringerc.id.au>
Re: Create view is not accepting the parameter in postgres functions Chris Travers <chris.travers@gmail.com>
Re: Create view is not accepting the parameter in postgres functions Thomas Kellerer <spam_eater@gmx.net>
Re: Create view is not accepting the parameter in postgres functions Craig Ringer <ringerc@ringerc.id.au>
Re: Create view is not accepting the parameter in postgres functions "Divyaprakash Y" <divyaprakash.y@celstream.com>
Re: Create view is not accepting the parameter in postgres functions Misa Simic <misa.simic@gmail.com>
Re: Create view is not accepting the parameter in postgres functions Misa Simic <misa.simic@gmail.com>
Re: Create view is not accepting the parameter in postgres functions Merlin Moncure <mmoncure@gmail.com>
Re: Create view is not accepting the parameter in postgres functions Tom Lane <tgl@sss.pgh.pa.us>
Re: Create view is not accepting the parameter in postgres functions Merlin Moncure <mmoncure@gmail.com>
On Wed, Jun 13, 2012 at 12:31 AM, Divyaprakash Y
 wrote:
>
> Hi,
>
>
>
> Is the following postgres function correct?
>
>
>
> CREATE OR REPLACE FUNCTION "MyFun"("IdArgs" INTEGER)
>
>                 RETURNS SETOF "B" AS
>
> $BODY$
>
>                 CREATE VIEW "A"  AS SELECT * FROM "B" WHERE "Id" = $1;
>
>                 SELECT * FROM "B";
>
> $BODY$
>
>   LANGUAGE 'sql' VOLATILE
>
>   COST 100;
>
> ALTER FUNCTION "MyFun"(INTEGER) OWNER TO postgres;
>
>
>
> Where “B” is a table in the DB schema.
>
>
>
>
>
> Executing “select * from "MyFun"(1) “ throws the following error:
>
>
>
> ERROR:  there is no parameter $1
>
> LINE 2: ...W "A” AS SELECT * FROM "B" WHERE "Id" = $1;
>
>
>
> ----------------
>
>
>
> Where as the following function works fine:
>
>
>
> CREATE OR REPLACE FUNCTION "MyFun"("IdArgs" INTEGER)
>
>                 RETURNS SETOF "B" AS
>
> $BODY$
>
>                 CREATE VIEW "A"  AS SELECT * FROM "B" WHERE "Id" = 1;
>
>                 SELECT * FROM "B";
>
> $BODY$
>
>   LANGUAGE 'sql' VOLATILE
>
>   COST 100;
>
> ALTER FUNCTION "MyFun"(INTEGER) OWNER TO postgres;
>
>
>
> Where “Id” is hardcoded within the function.
>
>
>
> Is this expected? Please reply.

(this has absolutely nothing to do with named parameters)

The CREATE VIEW statement does not allow parameterized arguments
apparently.  If you want to do this, you have to switch to plpgsql and
use EXECUTE.

merlin
В списке pgsql-general по дате отправления
От: leaf_yxj
Дата:
От: Little, Douglas
Дата:
Сообщение: composite type use in pl/gpsql
FAQ