当前位置:网站首页>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)
这样实现的功能,是我能批量获取数据库里面的表名与字段以及字段描述等信息。
边栏推荐
猜你喜欢
地下管廊可视化管理系统搭建
Design and implementation of flower online sales management system
【openpyxl】过滤和排序
ArcGIS Pro 创建tpk
#yyds干货盘点#【愚公系列】2022年08月 Go教学课程 008-数据类型之整型
Mysql.慢Sql
Jvm.分析工具(jconsole,jvisualvm,arthas,jprofiler,mat)
Introduction to Qt (6) - Implementation of the lottery system
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 3 DF Problem Solving
容器技术真的是环境管理的救星吗?
随机推荐
微信小程序强制更新版本
Go项目配置管理神器之viper使用详解
如何做到构建的提速,再提速
只会懒汉式和饿汉式 你还不懂单例模式!
Elastic scaling of construction resources
Analysis of LENS CRA and SENSOR CRA Matching Problems
[Excel knowledge and skills] Convert text numbers to numeric format
NOR FLASH闪存芯片ID应用之软件保护场景
两个链表的第一个公共节点——LeetCode
二维数组实战项目--------《扫雷游戏》
14. Thymeleaf
[Data Visualization] Chart Design Principles
Dump file generation, content, and analysis
Pico 4更多参数曝光:Pancake+彩色透视,还有Pro版本
#yyds干货盘点#【愚公系列】2022年08月 Go教学课程 008-数据类型之整型
微信小程序内部A页面向内嵌H5页面跳转,并且传参
ADC和DAC记录
报错:Client does not support authentication protocol requested by server; consider upgrading MySQL cli
[Excel knowledge and skills] Convert "false" date to "true" date format
详解JDBC的实现与优化(万字详解)