当前位置:网站首页>SQL statement--get database table information, table name, column name, description comment, etc.
SQL statement--get database table information, table name, column name, description comment, etc.
2022-08-11 00:49:00 【data wanderer】
information_schemaDetails
import pandas as pdimport reimport psycopg2from sqlalchemy import create_engine# Link library account informationgongsi_engine = psycopg2.connect(dbname='kk_dw',user='*******',password='*****',host='***')# Read the required data table from the company databasetable_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.columnswhere table_schema='dwd'and table_name='dwd_store_other_in_storage_orders_detail'""",con=gongsi_engine)data[['table_name','column_name','udt_name']]
Get a description, etc.
data = pd.read_sql(r"""selecta.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 commentfrompg_namespace n left join pg_class con n.oid = c.relnamespaceleft join pg_attribute aon a.attrelid = c.oidleft join pg_description bon a.attrelid = b.objoid and a.attnum = b.objsubidleft join pg_type ton a.atttypid = t.oidwheren.nspname = 'dwd' --table_schemaand c.relname = 'dwd_store_o2o_sales_detail' -- table_nameand a.attnum > 0order bya.attnum;""",con=gongsi_engine)
The function implemented in this way is that I can obtain information such as table names, fields and field descriptions in the database in batches.
边栏推荐
- Analysis of LENS CRA and SENSOR CRA Matching Problems
- 【爬虫】scrapy创建运行爬虫、解析页面(嵌套url)、自定义中间件(设置UserAgent和代理IP)、自定义管道(保存到mysql)
- Jvm. Profiling tools (jconsole, jvisualvm, arthas, jprofiler, mat)
- 地下管廊可视化管理系统搭建
- 云原生-VMware虚拟机安装Kubesphere实战(一)
- 小程序onPageNotFound的坑
- [21 Days Learning Challenge] Half Insertion Sort
- 3d打印出现stl文件物体不是流形,意味着不是水密体...解决办法
- rhel7.0解决yum无法使用(system is not registered to Red Hat Subscription Management)
- 微信小程序获取当前页面的url和参数
猜你喜欢
Jvm. Profiling tools (jconsole, jvisualvm, arthas, jprofiler, mat)
Exceptions and exception handling mechanisms
Two-dimensional array combat project -------- "Minesweeper Game"
[Excel knowledge and skills] Convert text numbers to numeric format
使用mysql语句操作数据表(table)
Apache Commons Configuration Remote Code Execution Vulnerability (CVE-2022-33980) Analysis & Reproduction
① 数据库介绍 及 关系型数据库的关系代数表达式
Pico 4更多参数曝光:Pancake+彩色透视,还有Pro版本
③ 关系数据库标准语言SQL 数据查询(SELECT)
Apache Commons Configuration远程代码执行漏洞(CVE-2022-33980)分析&复现
随机推荐
分库分表ShardingSphere-JDBC笔记整理
Where can I download IEEE papers?
异常和异常处理机制
【C语言】探索数据的存储(整形篇)
Web APIs BOM- 操作浏览器之综合案例
还在用 Xshell?你 out 了,推荐一个更现代的终端连接工具,好用到爆!
Single-chip human-computer interaction--matrix key
[Excel knowledge and skills] Convert "false" date to "true" date format
input输入框超出部分用省略号表示以及判断内容是否有超出(PC端)
使用 BeanUtils 做属性拷贝,性能有点拉胯!
深度解析volatile关键字(保证够全面)
Two-dimensional array combat project -------- "Minesweeper Game"
关于编程本质那些事
How engineers treat open source
微信小程序获取当前页面的url和参数
2022.8.10-----leetcode.640
YOLOv5的Tricks | 【Trick10】从PyTorch Hub加载YOLOv5
力扣------值相等的最小索引
HW-蓝队工作流程(1)
SAP ABAP JSON 格式数据处理