Function that creates views

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"?
Gerwin Philippo [ Mo, 13 Juni 2005 11:03 ] [ ID #835098 ]

Re: Function that creates views

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"?
Ion Chalmers Freeman [ Mi, 15 Juni 2005 23:44 ] [ ID #838421 ]
Datenbanken » comp.databases.postgresql.sql » Function that creates views

Vorheriges Thema: many-t-many and joins
Nächstes Thema: Calling a stored procedure from another stored procedure...