Function that creates views
am 13.06.2005 11:03:38 von Gerwin Philippo
I would like to make a plpgsql function that creates views depending on
a parameter:
CREATE OR REPLACE FUNCTION "public"."function1" (integer) RETURNS
boolean AS'
begin
create or replace view vw_test as
select * from organisations where org_id = $1;
return true;
end;
What I want is that I call the functions with "1", it creates a view
that says:
select * from organisations where org_id = 1;
Instead, it now creates a view:
select * from organisations where org_id = $1;
How can I make the function use "1" instead of "$1"?
Re: Function that creates views
am 15.06.2005 23:44:37 von Ion Chalmers Freeman
What happens in you alias $1 to a local variable?
Gerwin Philippo wrote:
> I would like to make a plpgsql function that creates views depending on
> a parameter:
>
> CREATE OR REPLACE FUNCTION "public"."function1" (integer) RETURNS
> boolean AS'
> begin
> create or replace view vw_test as
> select * from organisations where org_id = $1;
> return true;
> end;
>
> What I want is that I call the functions with "1", it creates a view
> that says:
> select * from organisations where org_id = 1;
> Instead, it now creates a view:
> select * from organisations where org_id = $1;
> How can I make the function use "1" instead of "$1"?