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

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.

主站蜘蛛池模板: 石台县| 肇州县| 清水河县| 神农架林区| 淮安市| 敦煌市| 双牌县| 汝阳县| 凤翔县| 于都县| 墨竹工卡县| 桂平市| 含山县| 隆昌县| 墨脱县| 盱眙县| 新乡县| 朔州市| 牟定县| 东宁县| 新沂市| 腾冲县| 康乐县| 新龙县| 抚宁县| 岳阳县| 乐安县| 桦南县| 青神县| 阿拉善盟| 屯昌县| 宁波市| 西吉县| 乌兰察布市| 页游| 四子王旗| 河津市| 江油市| 苍南县| 都江堰市| 南投市|