当前位置:网站首页>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)这样实现的功能,是我能批量获取数据库里面的表名与字段以及字段描述等信息。
边栏推荐
猜你喜欢

工程师如何对待开源

SAS data processing technology (1)

Word set before the title page

#yyds干货盘点#【愚公系列】2022年08月 Go教学课程 008-数据类型之整型

镜头之滤光片---关于日夜两用双通滤光片

Jvm.分析工具(jconsole,jvisualvm,arthas,jprofiler,mat)

分布式.性能优化

Based on the SSM to reach the phone sales mall system

20张图,全面掌握MVCC原理!

Introduction to Qt (6) - Implementation of the lottery system
随机推荐
Pagoda Test-Building PHP Online Mock Exam System
从0开始设计JVM ,忘记名词跟上思路一次搞懂
C# JObject解析JSON数据
J9 Digital Theory: DAO governance is more like an ecological process: governance is native to the network and continues to evolve
networkmanager无法打开
构建资源的弹性伸缩
Apache Commons Configuration Remote Code Execution Vulnerability (CVE-2022-33980) Analysis & Reproduction
How to easily obtain the citation format of references?
[数据可视化] 图表设计原则
异常:try catch finally throws throw
Design and implementation of flower online sales management system
Shell 文本三剑客 Sed
nodejs项目连接mysql数据库
微信小程序获取当前页面的url和参数
[Data Visualization] Chart Design Principles
构建检测,无规矩不成方圆
Where can I download IEEE papers?
Elastic scaling of construction resources
Jvm.分析工具(jconsole,jvisualvm,arthas,jprofiler,mat)
分库分表ShardingSphere-JDBC笔记整理