我正在尝试python生成一个脚本,在redshift中生成unload命令。我不是一个专业的Python程序员。我需要在哪里生成卸载列表的所有列。如果列的名称是特定的,我需要替换为一个函数。我面临的挑战是在字典的最后一个条目后面加上“,”。有没有办法可以避免最后一个逗号?任何帮助都将不胜感激。在import psycopg2 from psycopg2.extras
import RealDictCursor
try:
conn = psycopg2.connect("dbname='test' port='5439' user='scott' host='something.redshift.amazonaws.com' password='tiger'");
except:
print "Unable to connect to the database"
conn.cursor_factory = RealDictCursor
cur = conn.cursor()
conn.set_isolation_level( psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT )
try:
cur.execute("SELECT column from pg_table_def where schema_name='myschema' and table_name ='tab1' " );
except:
print "Unable to execute select statement from the database!"
result = cur.fetchall()
print "unload mychema.tab1 (select "
for row in result:
for key,value in row.items():
print "%s,"%(value)
print ") AWS Credentials here on..."
conn.close()