PostgreSQL 查看表字段类型及注释

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

1SELECT 2 a.attname as 字段名, 3 format_type(a.atttypid,a.atttypmod) as 类型, 4 a.attnotnull as 非空, col_description(a.attrelid,a.attnum) as 注释 5FROM 6 pg_class as c,pg_attribute as a 7where 8 a.attrelid = c.oid 9 and 10 a.attnum>0 11 and 12 c.relname = '你的表名';

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

1select 2 c.relname 表名, 3 cast(obj_description(relfilenode,'pg_class') as varchar) 名称, 4 a.attname 字段, 5 d.description 字段备注, 6 concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from '\(.*\)')) as 列类型 7from 8 pg_class c, 9 pg_attribute a, 10 pg_type t, 11 pg_description d 12where 13 a.attnum>0 14 and 15 a.attrelid=c.oid 16 and 17 a.atttypid=t.oid 18 and 19 d.objoid=a.attrelid 20 and 21 d.objsubid=a.attnum 22 and 23 c.relname in ( 24 select 25 tablename 26 from 27 pg_tables 28 where 29 schemaname='public' 30 and 31 position('_2' in tablename)=0 32 ) 33order by c.relname,a.attnum;
点赞
收藏

评论区

加载中...

相关推荐

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

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

sql注入

反引号是个比较特别的字符,下面记录下怎么利用0x00SQL注入反引号可利用在分隔符及注释作用,不过使用范围只于表名、数据库名、字段名、起别名这些场景,下面具体说下1)表名payload:select\from\users\whereuser\_id1limit0,1;!(https://o

Java修道之路,问鼎巅峰,我辈代码修仙法力齐天

<center<fontcolor00FF7Fsize5face"黑体"代码尽头谁为峰,一见秃头道成空。</font<center<fontcolor00FF00size5face"黑体"编程修真路破折,一步一劫渡飞升。</font众所周知,编程修真有八大境界:1.Javase练气筑基2.数据库结丹3.web前端元婴4.Jav

SpringBoot自定义序列化的使用方式

场景及需求:项目接入了SpringBoot开发,现在需求是服务端接口返回的字段如果为空,那么自动转为空字符串。例如:\    {        "id":1,        "name":null    },    {        "id":2,        "name":"x