Глава 43. PL/Python — процедурный язык Python

Процедурный язык PL/Python позволяет писать функции Postgres Pro на языке Python.

Чтобы установить PL/Python в определённую базу данных, выполните команду CREATE EXTENSION plpythonu (но смотрите также Раздел 43.1).

Подсказка

Если язык устанавливается в template1, он будет автоматически установлен во все создаваемые впоследствии базы данных.

PL/Python представлен только в виде «недоверенного» языка, что означает, что он никаким способом не ограничивает действия пользователей, и поэтому он называется plpythonu. Доверенная вариация plpython может появиться в будущем, если в Python будет разработан безопасный механизм выполнения. Автор функции на недоверенном языке PL/Python должен позаботиться о том, чтобы эту функцию нельзя было использовать не по назначению, так как она может делать всё, что может пользователь с правами администратора баз данных. Создавать функции на недоверенных языках, таких как plpythonu, разрешено только суперпользователям.

Примечание

Пользователи, имеющие дело с исходным кодом, должны явно включить сборку PL/Python в процессе установки. (За дополнительными сведениями обратитесь к инструкциям по установке.) Пользователи двоичных пакетов могут найти PL/Python в отдельном модуле.

F.28. mchar

The mchar module provides additional data types for compatibility with Microsoft SQL Server (MS SQL).

F.28.1. Overview

This module has been designed to improve 1C Enterprise support, most popular Russian CRM and ERP system.

It implements types MCHAR and MVARCHAR, which are bug-to-bug compatible with MS SQL CHAR and VARCHAR respectively. Additionally, these types use the ICU library for comparison and case conversion, so their behavior is identical across different operating systems.

Postgres Pro also includes citext extension which provides types similar to MCHAR. But this extension doesn't emulate MS-SQL behavior concerning end-of-value whitespace.

Differences from Postgres Pro standard CHAR and VARCHAR are:

  • Case insensitive comparison

  • Handling of the whitespace at the end of string

  • These types are always stored as two-byte unicode value regardless of database encoding.

F.28.2. Additional types

  • mchar — analog of the MS SQL char type

  • mvarchar — analog of the MS SQL varchar type

F.28.3. MCHAR and MVARCHAR features

  • Defines length(str) function

  • Defines substr(str, pos[, length]) function

  • Defines || operator, which would be applied to concatenate any (mchar and mvarchar) arguments

  • Defines set of operators: <, <=, =, >=, > for case-insensitive comparison (ICU)

  • Defines set of operators: &<, &<=, &=, &>=, &> to case-sensitive comparison (ICU)

  • Implicit cast between mchar and mvarchar types

  • B-tree and Hash-index support

  • The LIKE [ESCAPE] operator support

  • The SIMILAR TO [ESCAPE] operator support

  • The ~ operator (POSIX regexp) support

  • Index support for the LIKE operator

F.28.4. Authors


      Oleg Bartunov 
      Teodor Sigaev