官术网_书友最值得收藏!

Moving functions to other schemas

As with many other database objects, it is possible to place a function into a schema that is different from the default one, which is public. All we need to do is either fully qualify the name of the function at the time it is created or issue an ALTER FUNCTION command.

Listing 19 shows the two ways to add the function f_greetings() to the schema my_library:

  1. By declaring the function with the schema qualifier before its name, such as my_library.f_greetings
  2. By issuing an ALTER FUNCTION SET SCHEMA command to move the function from one schema to another
      -- first ensure there is the schema
testdb=> CREATE SCHEMA my_library;
-- and then add the function to the schema
testdb=> CREATE OR REPLACE FUNCTION
my_library.f_greetings( who text )
RETURNS text AS $code$
BEGIN
RETURN 'Hello dear ' || who;
END $code$ LANGUAGE plpgsql IMMUTABLE;

-- or to move an already existing function
testdb=> ALTER FUNCTION f_greetings( text ) SET SCHEMA my_library;
Listing 19:  Declaring a function in a specific schema

For security reasons, it is not possible to change the schema of an existing function into the pg_temp one, since this would transform the function into a temporary one. Similarly, a function that has been already defined as temporary cannot be moved to a non-temporary schema.

主站蜘蛛池模板: 荣昌县| 衢州市| 宁陕县| 屏东市| 阿坝县| 长丰县| 前郭尔| 永丰县| 肇源县| 长垣县| 新和县| 深水埗区| 卫辉市| 当雄县| 乌鲁木齐县| 龙山县| 英山县| 博爱县| 阳西县| 枣阳市| 龙门县| 印江| 佛坪县| 白沙| 壶关县| 廊坊市| 南京市| 六安市| 肥东县| 洛隆县| 老河口市| 乌拉特后旗| 偃师市| 陈巴尔虎旗| 紫云| 北京市| 通州市| 措美县| 岐山县| 姜堰市| 高唐县|