首页 > 数据库 >pgsql获取数据所有的表的字段和字段属性

pgsql获取数据所有的表的字段和字段属性

时间:2023-11-23 11:33:47浏览次数:23  
标签:schema description attribute pgsql 获取数据 pg table 属性 name

select

DISTINCT ORDINAL_POSITION as rn,

table_name as "tb_name",

column_name as "en_name",

(case udt_name WHEN 'numeric' THEN 'number' WHEN 'decimal' THEN 'number' WHEN 'int4' THEN 'number' WHEN 'int8' THEN'number'WHEN 'timestamp' THEN 'datetime' WHEN 'date' THEN 'datetime' WHEN 'datetime' THEN 'datetime' ELSE 'string' END ) as "data_type",coalesce(character_maximum_length,numeric_precision,-1) as "data_length",

coalesce(numeric_scale,0) as "precision_length",

case when position('nextval' in column_default)>0 then '1' else '0' end as "is_identity",

case when b.pk_name is null then 0 else '1' end as "is_pk",

case is_nullable when 'NO' then '0' else '1' end as "is_null",

 

c.DeText as remarks,



b.description as description ,

COLUMN_DEFAULT as "default_value"

from information_schema.columns

left join (
--B.description as description,
SELECT DISTINCT A.table_name as pk_table_name,B.attname as colname,B.attnum as attnum,

B.description as description ,

CASE WHEN length(B.attname) >0 THEN 1 ELSE NULL END AS pk_name

FROM information_schema.columns A

LEFT JOIN(

SELECT pg_attribute.attname, pg_attribute.attnum,pg_description.description as description

FROM pg_index, pg_class, pg_attribute ,pg_description

WHERE 1=1

AND pg_index.indrelid = pg_class.oid

AND pg_attribute.attrelid = pg_class.oid

and pg_description.objoid=pg_attribute.attrelid and pg_description.objsubid=pg_attribute.attnum

AND pg_attribute.attnum = ANY (pg_index.indkey)

)B ON A.column_name = b.attname

WHERE A.table_schema = current_schema()

and is_nullable='NO'

) b on b.colname = information_schema.columns.column_name and b.pk_table_name = information_schema.columns.table_name
left join (

SELECT col_description(a.attrelid,a.attnum) as DeText,a.attname as attname, c.relname as tbname,
c.relname as relname

FROM pg_class as c,pg_attribute as a where a.attrelid = c.oid and a.attnum>0

)c on c.attname = information_schema.columns. column_name and c.relname=information_schema.columns.table_name

where table_schema=current_schema()

order by table_name,rn asc

标签:schema,description,attribute,pgsql,获取数据,pg,table,属性,name
From: https://www.cnblogs.com/springfox/p/17851180.html

相关文章

  • pgsql 和 mysql语法对比
    超全mysql转换postgresql数据库方案https://blog.csdn.net/weixin_42303757/article/details/128896250?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-4-128896250-blog-131395729.235%5Ev38%5Epc_relevant_anti_t......
  • WPF依赖附加属性
    依赖附加属性的定义可使用代码片段-propa快速生成,输入propa后按两次Tab键publicstaticintGetMyProperty(DependencyObjectobj){return(int)obj.GetValue(MyPropertyProperty);}publicstaticvoidSetMyProperty(Depende......
  • white-space属性
    white-space属性表csswhite-space这个css样式,用来设置element元素对内容中的空格的处理方式,有着几个可选值:normal,nowrap,pre,pre-wrap,pre-line没有设置white-space属性,则默认为white-space:normal。normal表示合并空格,多个相邻空格合并成一个空格,在源码中的换行作为空格处理......
  • 有趣的Java之@Autowired属性注入问题
    ......
  • C# 动态类添加属性
    1.定义JsonDataObject publicsealedclassJsonDataObject:DynamicObject{privatereadonlyDictionary<string,object>_properties;publicJsonDataObject(Dictionary<string,object>properties){_properties=properties;......
  • 三种办法遍历对象数组,获取数组对象中所有的属性值(key,value);四种方法查找对象数组里面
    一,获取对象数组中某属性的所有值如果是要获取具体第几个属性的值,倒是可以用arr[i].name的方法来实现。若是全部的属性的值,并返回一个新的数组嘞,思路是加循环遍历方法如下。1、from方法vararr=[{id:1,name:"小明"},{id:2......
  • 浏览器标签页切换获取数据
    refresh(){/*浏览器标签页切换会触发"visibilitychange"事件*/document.addEventListener('visibilitychange',e=>{//切换显示标签if(document.visibilityState==='visible'){this.getTabelData()......
  • Spring5学习随笔-事务属性详解(@Transactional)
    学习视频:【孙哥说Spring5:从设计模式到基本应用到应用级底层分析,一次深入浅出的Spring全探索。学不会Spring?只因你未遇见孙哥】第三章、Spring的事务处理1.什么是事务?事务是保证业务操作完整性的一种数据库机制事务的4特点:ACIDA原子性C一致性I隔离性D持久性2.如何......
  • 微信小程序 布局对齐属性
    1、效果展示2、代码展示<!-- 引用模板 import --><view class="content" ><view class="content-item" style="background: skyblue" > 1</view><view class="content-item" style="background: #ff0000" >......
  • CAD中查看图元属性、绘制region、绘制block、绘制xc
    一、选中图元,编辑,查看属性 二、面域命令:region选定一个封闭图形,回车 三、块的新建及编辑命令:block选定一个封闭图形,命名,确定 四、XC前提:对块进行操作命令:xclip......