postgres temp function

PostgreSQL:一時関数 create temp function | 作業日報

一時的な関数を利用したい場合は pg_tempスキーマを利用できる、但しVer 8.2.4以降。
drop function if exists pg_temp.test(int);

create function pg_temp.test(int) returns integer as $$
begin
return $1+1;
end
$$ language 'plpgsql';

select pg_temp.test(1);
 pg_tempの存在はセキュリティ上問題になる可能性があるのでパスの検索順では一番下位にしておいたほうがよいようです。
SET search_path TO public,pg_temp;

PERFORM pg_catalog.set_config('search_path', 'admin, pg_temp', true);

PostgreSQL: Documentation: 8.3: CREATE FUNCTION

PostgreSQL has no CREATE TEMPORARY FUNCTION statement but you can get similar behavior by creating the function in the pg_temp schema:

CREATE FUNCTION pg_temp.increment(integer) returns integer as $$ select $1 + 1 $$ language SQL;

When created this way the function persists until the connection is closed and is only visible to the creating client. Each client can create its own version of the function without risk of name collision.

Functions created this way must be referenced with the fully-qualified schema. SELECT pg_temp.increment(5); will work but SELECT increment(5); will not.