不直接使用表名访问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()

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

相关内容

热门资讯

透视好友房!wepoker有脚... 透视好友房!wepoker有脚本吗(透视)拱趴大菠萝有辅助吗(总是有辅助安装)-哔哩哔哩1、实时拱趴...
透视数据!wepoker辅助器... 透视数据!wepoker辅助器安装包(透视)宝宝斗场辅助器(原来有辅助工具)-哔哩哔哩1、金币登录送...
据权威媒体报道!wpk控制牌是... 据权威媒体报道!wpk控制牌是真的吗(透视)永胜联盟辅助软件(好像有辅助辅助器)-哔哩哔哩1、打开软...
透视脚本!aapoker破解侠... 透视脚本!aapoker破解侠是真的吗(透视)乐达app辅助(都是真的有辅助修改器)-哔哩哔哩1、完...
透视插件!werplan怎么透... 透视插件!werplan怎么透视(透视)威信茶馆透视挂(确实是有辅助app)-哔哩哔哩在进入威信茶馆...
透视安卓版!哈糖大菠萝能开挂吗... 透视安卓版!哈糖大菠萝能开挂吗(透视)皇豪互娱辅助怎么设置(都是是有辅助辅助器)-哔哩哔哩1、皇豪互...
目前来看!wepoker透视脚... 目前来看!wepoker透视脚本免费下载pc(透视)楚天游卡五星辅助器(真是是有辅助插件)-哔哩哔哩...
据报道!pokerrrr2辅助... 据报道!pokerrrr2辅助(透视)微乐家乡麻辣自建房辅助app(切实是真的辅助神器)-哔哩哔哩1...
透视好友!werplan怎么作... 透视好友!werplan怎么作必弊(透视)开心泉州作必弊(本来存在有辅助安装)-哔哩哔哩1、让任何用...
透视新版!wepoker私人局... 透视新版!wepoker私人局可以透视(透视)西部透视辅助(果然是有辅助软件)-哔哩哔哩在进入西部透...