PG 常用命令

---------------pg 常用语句------------------
1. 查看表信息
select  * from pg_tables t where t.schemaname ='sdata';

2. 查看字段信息
select *
  from information_schema.columns t1
where t1.table_catalog ='dw'
   and t1.table_schema ='sdata'
   and t1.table_name ='user_table_name001'
  limit 10;
 
----------------------
一:查看表结构(字段)信息:
Select table_name,
       column_name,
       data_type,
       character_maximum_length
  from information_schema.columns
where table_schema='sdata'
   and table_name='user_table_name001';
   
二:查看字段注释信息:
Select a.attnum,(select description
                   from pg_catalog.pg_description
                  where objoid=a.attrelid
                    and objsubid=a.attnum
                 ) as descript ,
      a.attname,
      pg_catalog.format_type(a.atttypid,a.atttypmod) as data_type
  from pg_catalog.pg_attribute a
where 1=1
   and a.attrelid=(select oid from pg_class where relname='user_table_name001' )
   and a.attnum>0
   and not a.attisdropped
order by a.attnum;
-----------------------------------

-- 查询所有表注释
SELECT tb.table_name,
       d.description
  FROM information_schema.tables tb
  JOIN pg_class c
    ON c.relname = tb.table_name
  LEFT JOIN pg_description d
         ON d.objoid = c.oid
        AND d.objsubid = '0'
WHERE tb.table_schema = 'sdata';
-- 查询高频字段信息
SELECT col.column_name,
       count(*)
FROM information_schema.columns col
JOIN pg_class c
   ON c.relname = col.table_name
WHERE col.table_schema = 'sdata'
  and col.table_name like '%common_coupon_info'
GROUP BY col.column_name;

-- 查询所有列注释
SELECT col.table_name,
       col.column_name,
       col.ordinal_position AS o,
       d.description,
       COALESCE(col.udt_name||'('||col.character_maximum_length||')',col.udt_name)  as udt_name2   -- 字段属性
FROM information_schema.columns col
JOIN pg_class c
   ON c.relname = col.table_name
LEFT JOIN pg_description d
        ON d.objoid = c.oid
       AND d.objsubid = col.ordinal_position
WHERE col.table_schema

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值