文档

注释Comment

更新时间:

本文为您介绍Hologres中注释Comment使用相关内容。

语法介绍

在Hologres中,支持给内部表、外部表、列增加注释(Comment),命令语法如下。语法与PostgreSQL一致,详情请参见COMMENT。Comment可以在建表时使用,也可以建完表之后单独执行。

BEGIN;
CREATE TABLE[schema_name.] table_name (
[{ column_name column_type[column_constraints,[...]] | table_constraints[,...] }]
);
COMMENT ON COLUMN < tablename.column > IS 'value';--给列加注释 

COMMENT ON TABLE < tablename > IS 'value';--给表加注释

COMMIT;

使用示例

  • 建表时添加注释

    BEGIN;
    CREATE TABLE public."user" (
     "id" text NOT NULL,
     "name" text NOT NULL
    );
    COMMENT ON TABLE public."user" IS '用户属性表';
    COMMENT ON COLUMN public."user".id IS '身份证号';
    COMMENT ON COLUMN public."user".name IS '姓名';
    COMMIT;
  • 单独执行添加注释。

    -- 给表增加注释
    COMMENT ON TABLE table_name IS 'my comments on table table_name.';
    
    -- 给列增加注释
    COMMENT ON COLUMN table_name.col1 IS 'This my first col1';
    
    -- 给外部表增加注释
    COMMENT ON FOREIGN TABLE foreign_table IS ' comments on my foreign table';

通过系统表查看注释

可以通过系统表查看为表、列设置的注释,命令示例如下。

SELECT a.attname AS Column,
  pg_catalog.format_type(a.atttypid, a.atttypmod) AS "Type",
  a.attnotnull AS "Nullable",
  pg_catalog.col_description(a.attrelid, a.attnum) AS "Description"
FROM pg_catalog.pg_attribute a
WHERE a.attnum > 0 AND NOT a.attisdropped AND a.attrelid = '<schema.tablename>'::regclass::oid
ORDER BY a.attnum;
  • 本页导读 (1)