当前位置:网站首页>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.
边栏推荐
- MSTP——多生成树(案列+配置)
- Volatile和CAS
- More parameter exposure of Pico 4: Pancake + color perspective, and Pro version
- Linux安装redis数据库
- 2022.8.10-----leetcode.640
- Software protection scenario of NOR FLASH flash memory chip ID application
- SQL语句--获取数据库表信息,表名、列名、描述注释等
- 二维数组实战项目--------《扫雷游戏》
- 深度解析volatile关键字(保证够全面)
- 16. Sum of the nearest three numbers
猜你喜欢

rhel7.0解决yum无法使用(system is not registered to Red Hat Subscription Management)

Pico 4更多参数曝光:Pancake+彩色透视,还有Pro版本

什么是“门”电路(电子硬件)

容器技术真的是环境管理的救星吗?

WebView2 通过 PuppeteerSharp 实现RPA获取壁纸 (案例版)

Shell编程三剑客之sed

C# using timer

Some Experiences of Embedded Software Logging

Where can I download IEEE papers?

More parameter exposure of Pico 4: Pancake + color perspective, and Pro version
随机推荐
dump_stack()
ArcGIS Pro 创建tpk
url转成obj或者obj转成url的方法
[GXYCTF2019]BabySQli
云原生-FRP内网穿透(详解)使用云服务器将内网集群服务暴露至公网(二)
Introduction to Qt (6) - Implementation of the lottery system
HW-常见攻击方式和漏洞原理(2)
Use mysql statement to operate data table (table)
关于科研学习中的几个问题:如何看论文?如何评价工作?如何找idea?
How to build speed, speed up again
分库分表ShardingSphere-JDBC笔记整理
[21-day learning challenge - kernel notes] (5) - devmem read and write register debugging
时间戳转换为日期格式、获取当前时间戳
力扣------用栈操作构建数组
Ali P7 bask in January payroll: hard to fill the, really sweet...
16. Sum of the nearest three numbers
C#-委托的详细用法
Apache Commons Configuration远程代码执行漏洞(CVE-2022-33980)分析&复现
EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monocular Object Pose Est...
Pagoda Test-Building PHP Online Mock Exam System