主頁 > 知識庫 > 使用PostgreSQL為表或視圖創(chuàng)建備注的操作

使用PostgreSQL為表或視圖創(chuàng)建備注的操作

熱門標(biāo)簽:海豐有多少商家沒有地圖標(biāo)注 辦公外呼電話系統(tǒng) 重慶自動外呼系統(tǒng)定制 美容工作室地圖標(biāo)注 打電話智能電銷機(jī)器人授權(quán) 外呼調(diào)研系統(tǒng) 漯河外呼電話系統(tǒng) 地圖標(biāo)注和圖片名稱的區(qū)別 合肥公司外呼系統(tǒng)運(yùn)營商

1 為表和列創(chuàng)建備注

drop table if exists test;
create table test(
  objectid serial not null,
  num integer not null,
 constraint pk_test_objectid primary key (objectid),
 constraint ck_test_num check(num  123 ),
);
comment on table test is '我是表';
comment on column test.objectid is '我是唯一主鍵';
comment on column test.num is '數(shù)量字段';
comment on constraint pk_test_objectid on test is '我是約束,唯一主鍵';
comment on constraint ck_test_num on test is '我是約束,num字段必須小于123';
\dS+ test;

2 為視圖和列創(chuàng)建備注

drop view if exists vtest;
create or replace view vtest
 as select 1 as col1, 'a' as col2, now() as col3;
comment on view vtest is '視圖備注';
comment on column vtest.col1 is '第一列備注,integer類型';
comment on column vtest.col2 is '第二列備注,字符類型';
comment on column vtest.col3 is '第三列備注,日期時間類型';

3 comment語法

COMMENT ON
{
 ACCESS METHOD object_name |
 AGGREGATE aggregate_name ( aggregate_signature ) |
 CAST (source_type AS target_type) |
 COLLATION object_name |
 COLUMN relation_name.column_name |
 CONSTRAINT constraint_name ON table_name |
 CONSTRAINT constraint_name ON DOMAIN domain_name |
 CONVERSION object_name |
 DATABASE object_name |
 DOMAIN object_name |
 EXTENSION object_name |
 EVENT TRIGGER object_name |
 FOREIGN DATA WRAPPER object_name |
 FOREIGN TABLE object_name |
 FUNCTION function_name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] |
 INDEX object_name |
 LARGE OBJECT large_object_oid |
 MATERIALIZED VIEW object_name |
 OPERATOR operator_name (left_type, right_type) |
 OPERATOR CLASS object_name USING index_method |
 OPERATOR FAMILY object_name USING index_method |
 POLICY policy_name ON table_name |
 [ PROCEDURAL ] LANGUAGE object_name |
 PUBLICATION object_name |
 ROLE object_name |
 RULE rule_name ON table_name |
 SCHEMA object_name |
 SEQUENCE object_name |
 SERVER object_name |
 STATISTICS object_name |
 SUBSCRIPTION object_name |
 TABLE object_name |
 TABLESPACE object_name |
 TEXT SEARCH CONFIGURATION object_name |
 TEXT SEARCH DICTIONARY object_name |
 TEXT SEARCH PARSER object_name |
 TEXT SEARCH TEMPLATE object_name |
 TRANSFORM FOR type_name LANGUAGE lang_name |
 TRIGGER trigger_name ON table_name |
 TYPE object_name |
 VIEW object_name
} IS 'text'
where aggregate_signature is:
* |
[ argmode ] [ argname ] argtype [ , ... ] |
[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]

注意:SQL 標(biāo)準(zhǔn)中沒有COMMENT命令。

補(bǔ)充:postgre 查詢注釋_PostgreSQL查詢表以及字段的備注

查詢所有表名稱以及字段含義

select c.relname 表名,cast(obj_description(relfilenode,'pg_class') as varchar) 名稱,a.attname 字段,d.description 字段備注,concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from '.∗')) as 列類型 from pg_class c,pg_attribute a,pg_type t,pg_description d
where a.attnum>0 and a.attrelid=c.oid and a.atttypid=t.oid and d.objoid=a.attrelid and d.objsubid=a.attnum
and c.relname in (select tablename from pg_tables where schemaname='public' and position('_2' in tablename)=0) order by c.relname,a.attnum

查看所有表名

select tablename from pg_tables where schemaname='public' and position('_2' in tablename)=0;
select * from pg_tables;

查看表名和備注

select relname as tabname,cast(obj_description(relfilenode,'pg_class') as varchar) as comment from pg_class c
where relname in (select tablename from pg_tables where schemaname='public' and position('_2' in tablename)=0);
select * from pg_class;

查看特定表名備注

select relname as tabname,
cast(obj_description(relfilenode,'pg_class') as varchar) as comment from pg_class c
where relname ='表名';

查看特定表名字段

select a.attnum,a.attname,concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from '.∗')) as type,d.description from pg_class c,pg_attribute a,pg_type t,pg_description d
where c.relname='表名' and a.attnum>0 and a.attrelid=c.oid and a.atttypid=t.oid and d.objoid=a.attrelid and d.objsubid=a.attnum;

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • PostgreSQL 更新視圖腳本的注意事項說明
  • PostgreSQL物化視圖(materialized view)過程解析
  • PostgreSQL教程(十六):系統(tǒng)視圖詳解
  • PostgreSQL 修改視圖的操作

標(biāo)簽:蚌埠 晉城 株洲 珠海 來賓 烏海 錦州 衡陽

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《使用PostgreSQL為表或視圖創(chuàng)建備注的操作》,本文關(guān)鍵詞  使用,PostgreSQL,為,表,或,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《使用PostgreSQL為表或視圖創(chuàng)建備注的操作》相關(guān)的同類信息!
  • 本頁收集關(guān)于使用PostgreSQL為表或視圖創(chuàng)建備注的操作的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章