我正在尝试获取 Postgres DB 中存储过程中每一行的字段。我不断收到“元组索引超出范围”我基本上是从教程网站复制和粘贴代码,但仍然遇到相同的错误。
当我只做 row[0] 时,它会打印出整个查询。
ConfRoom = ("ConfRoom1",612,1589540397,1589540425,/var/lib/freeswitch/recordings/10.91.50.217/archive/2020/May/15/7b4def4e-0494-439f-8540-1f339e3ec375,1a4652e7-61fc-4fb8-b564-19adec09ec0e)
tuple index out of range
#!/usr/bin/python3
import psycopg2
from config import config
def connect():
""" Connect to the PostgreSQL database server """
conn = None
try:
# read connection parameters
params = config()
# connect to the PostgreSQL server
conn = psycopg2.connect(**params)
# create a cursor
cur = conn.cursor()
# execute a statement
postgreSQL_select_Query = 'SELECT "public"."fn_get_recordings"()'
cur.execute(postgreSQL_select_Query)
conf_query = cur.fetchall()
print(conf_query)
for row in conf_query:
print("ConfRoom = ", row[0], )
print("ConfDescription = ", row[1])
print("StartEpoch = ", row[2])
print("EndEpoch = ", row[3])
print("Location = ", row[4])
print("MeetingID = ", row[5], "\n")