欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PG判断常见数据库对象是否存在

程序员文章站 2022-03-03 20:12:01
...
  • 判断某个表是否存在
select  * from pg_tables where tablename='tbl_res';
  • 判断某个表的某个字段是否存在
SELECT attname FROM pg_attribute WHERE attname = 'autoid' and  attrelid = 'tbl_version'::regclass;
  • 判断某个表的某个约束是否存在
SELECT conname FROM pg_constraint WHERE conname = 'fk_tbl_ec_info_dev_code' and  conrelid = 'tbl_ec_info'::regclass;
  • 判断某个表的索引是否存在
select * from pg_indexes where tablename='tbl_operlog' and indexname='idx_tbl_operlog_oper_time_operlog_id';
  • 判断某个函数是否存在
select * from pg_proc where proname='func_get_id';
  • 判断某个触发器是否存在
select tgrelid::regclass,tgname, (select proname from pg_proc where oid =tgfoid)  from pg_trigger where tgname='tri_res_name_2_pinyin';
  • 判断某个视图是否存在
select * from pg_views where viewname='videorestable';
  • 判断某个类型是否粗在
select * from pg_type where typname='imos_code';
  • 判断某个序列是否存在
select * FROM information_schema.sequences where  sequence_name='seq_tbl_bank_alarm_record_alarm_id';
相关标签: PG数据库对象