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

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

相关内容

热门资讯

透视解迷"werpl... 透视解迷"werplan免费挂下载"其实存在有辅助软件(哔哩哔哩)亲,关键说明,werplan免费挂...
连日来"pokemo... 连日来"pokemomo辅助工具"约局吧德州可以透视吗(一贯是真的辅助软件)-哔哩哔哩1、打开软件启...
透视普及"hhpok... 透视普及"hhpoker是真的假的"本来真的有辅助攻略(哔哩哔哩)1、在hhpoker是真的假的插件...
反观"poker辅助... 反观"poker辅助器免费安装"约局吧辅助器(一贯是有辅助工具)-哔哩哔哩1、这是跨平台的poker...
透视开挂"hhpok... 透视开挂"hhpoker外开挂靠谱吗"切实有辅助教程(哔哩哔哩)1、在hhpoker外开挂靠谱吗插件...
辅助透视"wepok... 辅助透视"wepoker有用吗"wepokerplus到底是挂了吗(本来真的有辅助下载)-哔哩哔哩1...
透视有挂"wepok... 透视有挂"wepoker破解器"一贯存在有辅助脚本(哔哩哔哩)1、超多福利:超高返利,海量正版游戏,...
据文件显示"wepo... 据文件显示"wepoker有用吗"wepoker正确养号方法(竟然有辅助辅助器)-哔哩哔哩1、让任何...
透视专业"wepok... 透视专业"wepokerplus脚本"原来是真的辅助方法(哔哩哔哩)一、wepokerplus脚本游...
透视游戏"如何下载德... 透视游戏"如何下载德普之星辅助软件"wepoker轻量版辅助(一贯是真的辅助修改器)-哔哩哔哩1)如...