Search Postgresql Archives

How do write schema independent install files for functions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I have a number of functions which I wish to wrap up in a SQL script
(well technically DDL script).  The functions reference one another and
for safety it is necessary for them to ether set the search_path or
directly reference the schema for one another.

I was wondering if there is good / recommended way to write the install
script to easily install to an arbitrary schema.

The problem I have is that some functions need to set the search_path
for code security. As an example below, the function "bar()" needs to
set search_path or it would accidently reference the wrong "foo()".
However in order to install the same functions to a different schema I
would have to re-write the script with numerous changes to the various
"set search_path = my_schema" lines.


SET search_path = my_schema;

CREATE OR REPLACE FUNCTION foo()
  RETURNS INTEGER AS
$BODY$
BEGIN
	RETURN 42;
END;
$BODY$
  LANGUAGE plpgsql IMMUTABLE
  COST 100;

CREATE OR REPLACE FUNCTION bar()
  RETURNS INTEGER AS
$BODY$
BEGIN
	RETURN foo();
END;
$BODY$
  LANGUAGE plpgsql IMMUTABLE
  SET search_path = my_schema
  COST 100;


Is there any more flexible way to do this?

Thanks

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux