CREATE EXTENSION
Create an extension.
Summary
CREATE EXTENSION [ IF NOT EXISTS ] extension_name
[ WITH ] [ SCHEMA schema_name ]
[ VERSION version ]
[ FROM old_version ]
[ CASCADE ]
describe
CREATE EXTENSION loads the new extension into the current database. Extensions with the same name cannot be loaded.
Loading an extension is essentially equivalent to running an extension script file. This script usually creates new SQL objects such as functions, data types, operators and index-supported methods. The CREATE EXTENSION command also records the identity of all created objects, so if DROP EXTENSION is executed, they can be deleted again.
Loading an extension requires the same privileges as creating a component extension object. For most extensions, this means superuser or database owner privileges are required. The user running CREATE EXTENSION will become the owner of the extension for future permission checks, as well as the owner of any object created by the extension script.
Parameters
IF NOT EXISTS
- If an extension with the same name already exists, please do not report an error. In this case, a notice is issued. There is no guarantee that existing extensions are similar to installed extensions.
extension_name
- The extension to be installed. This name must be unique in the database. Create an extension based on the details in the extension control file SHAREDIR/extension/extension_name.control.
SHAREDIR is to install shared data directories, such as usr/local/matrixdb/share/postgresql (YMatrix 4.X path) or /opt/ymatrix/matrixdb5/share/postgresql (YMatrix 5.X path). The command pg_config --sharedir displays the directory.
SCHEMA schema_name
- The schema name in which the extension object is installed. Assume that the extension allows its content to be relocated. The naming pattern must already exist. If not specified and the extension control file does not specify a schema, the object is created using the current default schema.
If the extension specifies a pattern parameter in its control file, the pattern cannot be overwritten with the SCHEMA clause. Typically, if a SCHEMA clause is given and conflicts with the extended mode parameter, an error is thrown. However, if the CASCADE clause is also given, the schema_name will be ignored in conflict. The given schema_name is used to install all required extensions that do not specify a schema in its control file. The extension itself is not in any mode. Extensions have non-qualified names that must be unique in the database. But objects belonging to extensions can be in the pattern.
VERSION version
- The version of the extension to be installed. It can be written as an identifier or string literal. The default version is the value specified in the extension control file.
FROM old_version
- Specify FROM old_version only when trying to install an extension to replace an extension that is an extension that is not packaged into an object collection in the extension. If specified, CREATE EXTENSION runs an alternative installation script that absorbs existing objects into the extension rather than creating new objects. Make sure that the SCHEMA clause specifies a schema containing these pre-existing objects.
The value used for old_version is determined by the extension author, which may vary if multiple older versions of modules can be upgraded to extensions. For standard add-on modules provided by PostgreSQL before 9.1, when updating the module to an extended style, please specify unpackaged for old_version.
CASCADE
- Automatic installation related extensions have not been installed yet. Recursively check for related extensions, and these slave extensions will also be automatically installed. If the SCHEMA clause is specified, this pattern applies to extensions and all dependent extensions that have been installed. The other options specified do not apply to the automatically installed slave extensions. In particular, always select the default version when installing slave extensions.
Note
The extension currently available for loading can be recognized from the pg_available_extensions or pg_available_extension_versions system views.
Before loading an extension to the database using CREATE EXTENSION, the supported extension files must be installed, including the extension control files and at least one SQL script file. Support files must be installed in the same location on all MatrixDB database hosts.
compatibility
CREATE EXTENSION is a YMatrix database extension.
See also
ALTER EXTENSION , DROP EXTENSION