当前位置:网站首页>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.
边栏推荐
- 分库分表ShardingSphere-JDBC笔记整理
- 2022.8.10-----leetcode.640
- 【js】获取当前时间的前后n天或前后n个月(时分秒年月日都可)
- 总结Qt中常用文件信息QFileInfo的获取:后缀,名称,路径,链接
- 【.NET Core】使用 NPOI 读写Excel 文件
- How engineers treat open source
- How to do patent mining, the key is to find patent points, in fact, it is not too difficult
- Lens filter---about day and night dual-pass filter
- EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monocular Object Pose Est...
- 微信小程序通过URL Scheme动态的渲染数据
猜你喜欢

② 关系数据库标准语言SQL 数据定义(创建、修改基本表)、数据更新(增删改)

力扣------用栈操作构建数组
![[GXYCTF2019]BabySQli](/img/8a/7500c0ee275d6ef8909553f34c99cf.png)
[GXYCTF2019]BabySQli

微信小程序通过URL Scheme动态的渲染数据

Introduction to Qt (6) - Implementation of the lottery system

Why do programming languages have the concept of variable types?

ArcGIS Pro 创建tpk

微信小程序自定义navigationBar

Mysql.慢Sql

Jvm. Profiling tools (jconsole, jvisualvm, arthas, jprofiler, mat)
随机推荐
【ASM】字节码操作 ClassWriter COMPUTE_FRAMES 的作用 与 visitMaxs 的关系
【爬虫】scrapy创建运行爬虫、解析页面(嵌套url)、自定义中间件(设置UserAgent和代理IP)、自定义管道(保存到mysql)
WinForm(五)控件和它的成员
Shell编程三剑客之sed
详解JDBC的实现与优化(万字详解)
Two-dimensional array combat project -------- "Minesweeper Game"
Elastic scaling of construction resources
什么是“门”电路(电子硬件)
@Autowired注入RedisCache报错空指针
【.NET Core】使用 NPOI 读写Excel 文件
【mysql】mysql分别按年/月/日/周分组统计数据
[GXYCTF2019]BabySQli
报错:Client does not support authentication protocol requested by server; consider upgrading MySQL cli
Dump文件生成,内容,以及分析
微信小程序强制更新版本
SystemVerilog: 验证知识点点滴滴
word 设置标题前分页
Use mysql statement to operate data table (table)
C#使用计时器
electron -autoUpdater 更新