不直接使用表名访问PostgreSQL表。
创始人
2025-01-12 12:00:18
0

可以使用PostgreSQL元数据系统中的信息来访问表,例如查询sys.tables视图获取表的信息,然后使用该信息来访问表。以下是一个使用Python语言的示例代码:

import psycopg2

# Connect to the PostgreSQL database
conn = psycopg2.connect(database="mydb", user="myuser", password="mypassword", host="localhost", port="5432")
cur = conn.cursor()

# Get information about the table
cur.execute("SELECT * FROM sys.tables WHERE table_name = 'mytable'")
table_info = cur.fetchone()

# Use the information to access the table
table_name = table_info[0] # Assuming the table name is in the first column
cur.execute("SELECT * FROM " + table_name)

# Use the table data
for row in cur.fetchall():
    print(row)

# Close the database connection
conn.close()

请注意,这只是一个示例,实际上访问表时应该更复杂和安全。

相关内容

热门资讯

昨日!拱趴大菠萝有什么挂,微乐... 昨日!拱趴大菠萝有什么挂,微乐游戏竞技团辅助,透视脚本(有挂秘笈)-哔哩哔哩一、拱趴大菠萝有什么挂可...
透视详情!hhpoker透视工... 透视详情!hhpoker透视工具,hhpoker透视工具(透视)总是真的有app(哔哩哔哩)1、下载...
目前!wpk透视辅助下载,微信... 目前!wpk透视辅助下载,微信小程序微乐破解器,关于脚本(有挂解密)-哔哩哔哩1、让任何用户在无需w...
脚本推荐!aapoker怎么开... 脚本推荐!aapoker怎么开辅助器,aapoker透视怎么用(透视)一贯真的是有脚本(哔哩哔哩)是...
昨日!wepoker手机助手,... 昨日!wepoker手机助手,微乐小程序授权,教你透视(的确有挂)-哔哩哔哩1、不需要AI权限,帮助...
透视有挂!德普之星辅助工具如何... 透视有挂!德普之星辅助工具如何打开,德扑之心免费透视(透视)真是真的有软件(哔哩哔哩)透视有挂!德普...
透视软件!pokermaste... 透视软件!pokermaster修改器,微乐自建房辅助入口在哪里,教你脚本(有人有挂)-哔哩哔哩1、...
脚本教你!aapoker辅助插... 脚本教你!aapoker辅助插件工具,aapoker怎么设置提高好牌几率(透视)果然是有攻略(哔哩哔...
更值得关注的是!wepoker... 更值得关注的是!wepoker俱乐部辅助,微乐a3纸牌有脚本,解迷透视(有挂猫腻)-哔哩哔哩1、进入...
透视解谜!aapoker ai... 透视解谜!aapoker ai插件,aapoker辅助工具安全吗(透视)好像存在有工具(哔哩哔哩)1...