Updated on 2025-10-23 GMT+08:00

CREATE RESOURCE LABEL

Description

CREATE RESOURCE LABEL is used to create a resource label. The current version does not support this syntax.

Precautions

Only users with the POLADMIN or SYSADMIN permission, or the initial user can perform this operation.

Syntax

1
CREATE RESOURCE LABEL [IF NOT EXISTS] label_name ADD label_item_list[, ...];

  • label_item_list
    1
    resource_type(resource_path[, ...])
    

  • resource_type
    { TABLE | COLUMN | SCHEMA | VIEW | FUNCTION }

Parameters

  • IF NOT EXISTS

    If a resource label with the same name already exists, no error is generated. Instead, a message is displayed, indicating that the resource label already exists.

  • label_name

    Specifies the resource label name, which must be unique.

    Value range: a string of no more than 63 characters. It must comply with the naming conventions. If the value contains more than 63 characters, the database truncates it and retains the first 63 characters as the resource label name. If a resource label name contains uppercase letters, the database automatically converts the uppercase letters into lowercase letters. To create a resource label name that contains uppercase letters, enclose the resource label name with double quotation marks ("").

    The identifier must be lowercase letters, uppercase letters, underscores (_), digits (0–9), or dollar signs ($) and must start with a letter or underscore (_).

  • resource_type

    Specifies the type of database resources to be labeled.

    Value range: TABLE, COLUMN, SCHEMA, VIEW, and FUNCTION.

  • resource_path

    Specifies the path of database resources.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-- Create table tb_for_label.
m_db=# CREATE TABLE tb_for_label(col1 text, col2 text, col3 text);

-- Create a resource label based on a table.
m_db=# CREATE RESOURCE LABEL IF NOT EXISTS table_label add TABLE(public.tb_for_label);

-- Create an existing table resource label again and compare the differences between adding IF NOT EXISTS and not adding IF NOT EXISTS.
m_db=# CREATE RESOURCE LABEL IF NOT EXISTS table_label add TABLE(public.tb_for_label);
NOTICE:  table_label label already defined, skipping
CREATE RESOURCE LABEL
m_db=# CREATE RESOURCE LABEL table_label add TABLE(public.tb_for_label);
ERROR:  table_label label already defined

-- Create a resource label based on columns.
m_db=# CREATE RESOURCE LABEL IF NOT EXISTS column_label add COLUMN(public.tb_for_label.col1);

-- Create schema schema_for_label.
m_db=# CREATE SCHEMA schema_for_label;

-- Create a resource label based on a schema.
m_db=# CREATE RESOURCE LABEL IF NOT EXISTS schema_label add SCHEMA(schema_for_label);

-- Create view view_for_label.
m_db=# CREATE VIEW view_for_label AS SELECT 1;

-- Create a resource label based on a view.
m_db=# CREATE RESOURCE LABEL IF NOT EXISTS view_label add VIEW(view_for_label);

-- Create function func_for_label.
m_db=# CREATE FUNCTION func_for_label RETURNS TEXT AS $$ SELECT col1 FROM tb_for_label; $$ LANGUAGE SQL;

-- Create a resource label based on a function.
m_db=# CREATE RESOURCE LABEL IF NOT EXISTS func_label add FUNCTION(func_for_label);

-- Drop the table resource label table_label.
m_db=# DROP RESOURCE LABEL IF EXISTS table_label; 

-- Drop the column resource label column_label.
m_db=# DROP RESOURCE LABEL IF EXISTS column_label;

-- Drop the function resource label func_for_label.
m_db=# DROP FUNCTION func_for_label;

-- Drop the view resource label view_for_label.
m_db=# DROP VIEW view_for_label;

-- Drop the schema resource label schema_for_label.
m_db=# DROP SCHEMA schema_for_label;

-- Drop the tb_for_label table.
m_db=# DROP TABLE tb_for_label;