++
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import psycopg2
|
||||
|
||||
# 数据库连接参数
|
||||
db_config = {
|
||||
'host': '192.168.31.201',
|
||||
'port': 5432,
|
||||
'database': 'alpha',
|
||||
'user': 'jack',
|
||||
'password': 'aaaAAA111'
|
||||
}
|
||||
|
||||
results = []
|
||||
|
||||
keys_list = []
|
||||
|
||||
try:
|
||||
# 连接数据库
|
||||
conn = psycopg2.connect(**db_config)
|
||||
# 创建游标
|
||||
cur = conn.cursor()
|
||||
|
||||
keys = [
|
||||
'占位'
|
||||
]
|
||||
|
||||
for key in keys:
|
||||
# SQL 查询语句
|
||||
sql = """
|
||||
select * from data_sets
|
||||
where name like '%{}%'
|
||||
""".format(key)
|
||||
|
||||
# 执行查询
|
||||
cur.execute(sql)
|
||||
|
||||
# 获取所有结果
|
||||
rows = cur.fetchall()
|
||||
|
||||
# 打印结果
|
||||
for row in rows:
|
||||
results.append({
|
||||
"name": row[1],
|
||||
"description": row[2],
|
||||
})
|
||||
|
||||
# 关闭游标和连接
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
except Exception as e:
|
||||
print("数据库连接或查询出错:", e)
|
||||
|
||||
for result in results:
|
||||
print(result)
|
||||
Reference in New Issue
Block a user