Глава 48. PL/Python — процедурный язык Python
Содержание
Процедурный язык PL/Python позволяет писать функции и процедуры Postgres Pro на языке Python.
Чтобы установить PL/Python в определённую базу данных, выполните команду CREATE EXTENSION plpythonu (но смотрите также Раздел 48.1).
Подсказка
Если язык устанавливается в template1, он будет автоматически установлен во все создаваемые впоследствии базы данных.
PL/Python представлен только в виде «недоверенного» языка, что означает, что он никаким способом не ограничивает действия пользователей, и поэтому он называется plpythonu. Доверенная вариация plpython может появиться в будущем, если в Python будет разработан безопасный механизм выполнения. Автор функции на недоверенном языке PL/Python должен позаботиться о том, чтобы эту функцию нельзя было использовать не по назначению, так как она может делать всё, что может пользователь с правами администратора баз данных. Создавать функции на недоверенных языках, таких как plpythonu, разрешено только суперпользователям.
Примечание
В Postgres Pro Enterprise поддерживаются языки plpythonu/plpython2u и plpython3u. Соответствующие расширения поставляются в виде отдельных пакетов postgrespro-ent-14-plpython и postgrespro-ent-14-plpython3, соответственно (подробные инструкции по установке приведены в Главе 17). Отличия вариаций языка PL/Python описаны в Разделе 48.1.
Chapter 48. PL/Python — Python Procedural Language
Table of Contents
The PL/Python procedural language allows Postgres Pro functions and procedures to be written in the Python language.
To install PL/Python in a particular database, use CREATE EXTENSION plpythonu (but see also Section 48.1).
Tip
If a language is installed into template1, all subsequently created databases will have the language installed automatically.
PL/Python is only available as an “untrusted” language, meaning it does not offer any way of restricting what users can do in it and is therefore named plpythonu. A trusted variant plpython might become available in the future if a secure execution mechanism is developed in Python. The writer of a function in untrusted PL/Python must take care that the function cannot be used to do anything unwanted, since it will be able to do anything that could be done by a user logged in as the database administrator. Only superusers can create functions in untrusted languages such as plpythonu.
Note
The plpythonu/plpython2u and plpython3u languages are supported in Postgres Pro Enterprise. The corresponding extensions are supplied as separate pre-built packages postgrespro-ent-14-plpython and postgrespro-ent-14-plpython3, respectively (for the detailed installation instructions, see Chapter 17). To learn about the differences between the PL/Python language variants, see Section 48.1.