本文為您介紹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;相關文檔
關於Hologres內部表DDL語句的介紹詳情,請參見: