下面的代码挂起(即使ctrl-C也不会停止它,我必须关闭终端)当它试图创建第二个表时,我不知道为什么。第一个表是成功创建的(我可以在带有\ dt蓝细菌的* psql中看到它。)。一个简单的解决方案是重命名表,但我正在尝试将其他人的代码恢复到正常工作状态,并且我必须通过更改大量内容来完成。而且他有一次工作,所以应该为我工作!
我创建了一个名为'genomes'的数据库,一个名为'genomes_admin'的用户和一个名为'cyanobacteria'的模式。然后我尝试制作一些表格:
#!/usr/bin/python
import psycopg2
psql = "dbname='genomes' user='genomes_admin'"
schm = 'cyanobacteria'
conn = psycopg2.connect(psql)
cur = conn.cursor()
cur.execute('''SET search_path TO %s''', (schm,))
conn.commit()
cur.execute('''CREATE TABLE IF NOT EXISTS testnm(blah text, length int) ''')
print 'created testnm'
conn.commit()
print 'committed'
cur.execute('''CREATE TABLE IF NOT EXISTS genomes(blah text, length int) ''') # hangs here
print 'created genomes' # this line never executes
conn.commit()
print 'committed'
cur.close()
conn.close()