CREATE EXTENSION
Function
CREATE EXTENSION installs an extension.
Precautions
- Before running the CREATE EXTENSION command to load an extension into the database, you must install the support file for the extension first.
- The CREATE EXTENSION command installs a new extension to a database. Ensure that no extension with the same name has been installed.
- Installing an extension means executing an extended script file that creates a SQL entity, such as a function, data type, operator, and index-supported method.
- Installing an extension requires the same permissions as creating its component objects. For most extensions, this means that the superuser or database owner's permissions are required. For subsequent permission checks and entities created by the extension script, the role that runs the CREATE EXTENSION command becomes the owner of the extension.
- During the execution of CREATE EXTENSION, if the database contains database objects with the same name as those in the EXTENSION, such as packages, synonyms, operators, directories, functions, stored procedures, views, and tables, the execution will fail.
Syntax
CREATE EXTENSION [ IF NOT EXISTS ] extension_name [ WITH ] [ SCHEMA schema_name ] [ VERSION version ] [ FROM old_version ]
Parameter Description
- IF NOT EXISTS
If an extension with the same name exists in the system, no error is reported. However, a message is displayed. Note that this parameter does not ensure that the existing extensions of the system are the same as those created by the script.
- extension_name
Specifies the name of the extension to be installed. The database creates the extension by using the information in the SHAREDIR/extension/extension_name.control file.
- schema_name
The extension instance is installed in this schema, and the extended content can be reinstalled. The specified schema must exist. If it is not specified, the extended control file does not specify a schema either. In this case, the default schema is used.
Extensions are not considered to be in any schema (no restriction is posed on the name of extensions within the scope of a database), but an extension instance belongs to a schema.
- version
Version of the extension to be installed, which can be written as an identifier or a string. The default version is specified in the extended control file.
- old_version
If you want to upgrade the content that is not contained in the old style module, you must specify FROM old_version. This option makes CREATE EXTENSION run an installation script to install new content into the extension instead of creating an entity. Note that SCHEMA specifies the schema that includes these existing entities.
Examples
Install the hstore extension in the current database.
CREATE EXTENSION hstore;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot