Create view is not accepting the parameter in postgres functions - Mailing list pgsql-general

From Divyaprakash Y
Subject Create view is not accepting the parameter in postgres functions
Date
Msg-id CCEE49B9CE065146BA4FE34B2748A5321417B4C6@CEL-BANGT-M01.celstream-in.com
Whole thread Raw
Responses 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  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-general

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.

 

Regards,

DP

 

______________________________________________________________________________DISCLAIMER: This electronic message and any attachments to this electronicmessage is intended for the exclusive use of the addressee(s) named hereinand may contain legally privileged and confidential information. It is the property of Celstream Technologies Pvt Limited. If you are not the intendedrecipient, you are hereby strictly notified not to copy, forward, distributeor use this message or any attachments thereto. If you have received thismessage in error, please delete it and all copies thereof, from your systemand notify the sender at Celstream Technologies or administrator@celstream.com immediately.
______________________________________________________________________________

pgsql-general by date:

Previous
From: Chris Travers
Date:
Subject: Re: How to create c language in postgresql database. Thanks.
Next
From: Stefan Schwarzer
Date:
Subject: Re: Problem installing extensions on Lion