PostgreSQL 查看表字段类型及注释

Stella981
• 阅读 1676

一、查看pg 表字段‘名称’、‘类型’、‘非空’、‘注释’

SELECT 
    a.attname as 字段名,
    format_type(a.atttypid,a.atttypmod) as 类型, 
    a.attnotnull as 非空, col_description(a.attrelid,a.attnum) as 注释   
FROM 
    pg_class as c,pg_attribute as a 
where 
    a.attrelid = c.oid 
    and 
    a.attnum>0 
    and 
    c.relname = '你的表名';

二、查看pg 某库 所有‘表名称’、‘字段名称‘以及‘字段注释’和‘字段类型’

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;
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Java修道之路,问鼎巅峰,我辈代码修仙法力齐天
<center<fontcolor00FF7Fsize5face"黑体"代码尽头谁为峰,一见秃头道成空。</font<center<fontcolor00FF00size5face"黑体"编程修真路破折,一步一劫渡飞升。</font众所周知,编程修真有八大境界:1.Javase练气筑基2.数据库结丹3.web前端元婴4.Jav
Easter79 Easter79
2年前
sql注入
反引号是个比较特别的字符,下面记录下怎么利用0x00SQL注入反引号可利用在分隔符及注释作用,不过使用范围只于表名、数据库名、字段名、起别名这些场景,下面具体说下1)表名payload:select\from\users\whereuser\_id1limit0,1;!(https://o
Easter79 Easter79
2年前
SpringBoot自定义序列化的使用方式
场景及需求:项目接入了SpringBoot开发,现在需求是服务端接口返回的字段如果为空,那么自动转为空字符串。例如:\    {        "id":1,        "name":null    },    {        "id":2,        "name":"x
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL数据库(三)
一、表结构修改(alter)1.修改表名:altertabletb_namerenametonew_name;2.修改字段名:altertabletb_namechangenamenew_namedata_type;3.修改字段类型:ALTERTABLEtb_nameMODIFYfield_nameda
Wesley13 Wesley13
2年前
ThinkPHP 根据关联数据查询 hasWhere 的使用实例
很多时候,模型关联后需要根据关联的模型做查询。场景:广告表(ad),广告类型表(ad\_type),现在需要筛选出广告类型表中id字段为1且广告表中status为1的列表先看关联的设置部分 publicfunctionadType(){return$thisbelongsTo('A
Stella981 Stella981
2年前
SpringBoot自定义序列化的使用方式
场景及需求:项目接入了SpringBoot开发,现在需求是服务端接口返回的字段如果为空,那么自动转为空字符串。例如:\    {        "id":1,        "name":null    },    {        "id":2,        "name":"x
Wesley13 Wesley13
2年前
MySQL导出表结构相关字段以及把字段由下划线转驼峰命名
SELECTCOLUMN_COMMENT中文名,UPPER(COLUMN_NAME)字段名,UPPER(DATA_TYPE)字段类型,CHARACTER_MAXIMUM_LENGTH长度,IS_NULLABLE是否为空FROMINFORMATION_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这