当前位置:网站首页>SQL语句--获取数据库表信息,表名、列名、描述注释等
SQL语句--获取数据库表信息,表名、列名、描述注释等
2022-08-11 00:39:00 【数据闲逛人】
import pandas as pd import re import psycopg2 from sqlalchemy import create_engine # 连接库账户信息 gongsi_engine = psycopg2.connect(dbname='kk_dw',user='*******',password='*****',host='***') # 从公司数据库读取需要的数据表 table_data = pd.read_sql(r"select * from pg_tables where schemaname = 'dwd';",con=gongsi_engine) table_data.head() data = pd.read_sql(r"""select * from information_schema.columns where table_schema='dwd' and table_name='dwd_store_other_in_storage_orders_detail'""",con=gongsi_engine) data[['table_name','column_name','udt_name']]
获取描述等
data = pd.read_sql(r"""select
a.attnum,
n.nspname,
c.relname,
a.attname as field,
t.typname as type,
a.attlen as length,
a.atttypmod as lengthvar,
a.attnotnull as notnull,
b.description as comment
from
pg_namespace n left join pg_class c
on n.oid = c.relnamespace
left join pg_attribute a
on a.attrelid = c.oid
left join pg_description b
on a.attrelid = b.objoid and a.attnum = b.objsubid
left join pg_type t
on a.atttypid = t.oid
where
n.nspname = 'dwd' --table_schema
and c.relname = 'dwd_store_o2o_sales_detail' -- table_name
and a.attnum > 0
order by
a.attnum;""",con=gongsi_engine)
这样实现的功能,是我能批量获取数据库里面的表名与字段以及字段描述等信息。
边栏推荐
- 详解JDBC的实现与优化(万字详解)
- Some Experiences of Embedded Software Logging
- In 22 years, the salary of programmers nationwide in January was released, only to know that there are so many with annual salary of more than 400,000?
- 【mysql】mysql分别按年/月/日/周分组统计数据
- NOR FLASH闪存芯片ID应用之软件保护场景
- 地下管廊可视化管理系统搭建
- C# using timer
- EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monocular Object Pose Est...
- Mysql. Slow Sql
- SAP ABAP JSON 格式数据处理
猜你喜欢
Jvm. Profiling tools (jconsole, jvisualvm, arthas, jprofiler, mat)
[Excel知识技能] 将数值格式数字转换为文本格式
[Data Visualization] Chart Design Principles
Shell Text Three Musketeers Sed
Pico 4更多参数曝光:Pancake+彩色透视,还有Pro版本
3d打印出现stl文件物体不是流形,意味着不是水密体...解决办法
J9 Digital Theory: DAO governance is more like an ecological process: governance is native to the network and continues to evolve
[Excel知识技能] 将文本型数字转换为数值格式
【openpyxl】过滤和排序
Mysql. Slow Sql
随机推荐
postgresql参数意义
Go项目配置管理神器之viper使用详解
Dump文件生成,内容,以及分析
[21-day learning challenge - kernel notes] (5) - devmem read and write register debugging
ArcGIS Pro 创建tpk
Navicat 16-数据库工具
异常:try catch finally throws throw
【21天学习挑战赛】折半插入排序
学习Apache ShardingSphere解析器源码(一)
Ali P7 bask in January payroll: hard to fill the, really sweet...
全排列思路详解
百战RHCE(第四十八战:运维工程师必会技-Ansible学习3-构建Ansible清单)
NOR FLASH闪存芯片ID应用之软件保护场景
Qt入门(六)——抽奖系统的实现
SAS data processing technology (1)
Mysql.慢Sql
【redis】发布和订阅消息
微信小程序内部A页面向内嵌H5页面跳转,并且传参
数据分析面试手册《SQL篇》
力扣------使用最小花费爬楼梯