- PostgreSQL 11 Server Side Programming Quick Start Guide
- Luca Ferrari
- 220字
- 2021-06-10 19:23:07
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:
- By declaring the function with the schema qualifier before its name, such as my_library.f_greetings
- 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.
推薦閱讀
- Mastering Spark for Data Science
- Getting Started with Clickteam Fusion
- Java實用組件集
- 返璞歸真:UNIX技術(shù)內(nèi)幕
- Zabbix Network Monitoring(Second Edition)
- 大數(shù)據(jù)安全與隱私保護(hù)
- Implementing Splunk 7(Third Edition)
- Splunk Operational Intelligence Cookbook
- 中國戰(zhàn)略性新興產(chǎn)業(yè)研究與發(fā)展·工業(yè)機器人
- 從零開始學(xué)C++
- Applied Data Visualization with R and ggplot2
- 電腦上網(wǎng)輕松入門
- Working with Linux:Quick Hacks for the Command Line
- 學(xué)練一本通:51單片機應(yīng)用技術(shù)
- 與人共融機器人的關(guān)節(jié)力矩測量技術(shù)