CREATE TYPE¶
Creates a user-defined type.
- See also:
ALTER TYPE , DESCRIBE TYPE , SHOW TYPES , DROP TYPE , UNDROP TYPE
语法
必填参数
name指定用户定义的类型的标识符;对于创建用户定义的类型时所在的架构来说,此标识符必须是唯一的。
The name can’t be the same as a Snowflake type name. For example, the type name can’t be
arrayorgeometry.If the name is the same as a Snowflake keyword, it must be specified in double quotes.
In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example,
"My object"). Identifiers enclosed in double quotes are also case-sensitive.For more information, see Identifier requirements.
AS typeAn existing Snowflake data type definition.
指定的类型定义是要创建的用户定义类型的 基类型。
typecan’t be another user-defined type.
可选参数
COMMENT = 'string_literal'指定用户定义类型的注释。
默认:无值
访问控制要求
A role used to execute this operation must have the following privileges at a minimum:
| 权限 | 对象 | 备注 |
|---|---|---|
| CREATE TYPE | 架构 |
Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema.
For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.
For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.
使用说明
- The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
-
CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.
-
关于元数据:
Attention
Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.
示例
使用 CREATE TYPE 命令创建基于 NUMBER 数据类型的用户定义类型:
创建基于 OBJECT 数据类型的用户定义类型:
For more examples, see Examples for user-defined data types.