Skip to content

Commit 980b577

Browse files
Added commit to actually save the table in the db
Need to add conn.commit() to save the table else when you go to view the table in a db manager it will not exsist
1 parent d3daceb commit 980b577

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

content/posts/160518-install-postgresql-python-3-ubuntu-1604.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ and "password" values with your own.
163163
cursor.execute("""CREATE TABLE tutorials (name char(40));""")
164164
# run a SELECT statement - no data in there, but we can try it
165165
cursor.execute("""SELECT * from tutorials""")
166+
conn.commit() # <--- makes sure the change is shown in the database
167+
conn.close()
168+
cursor.close()
166169
rows = cursor.fetchall()
167170
print(rows)
168171
except Exception as e:

0 commit comments

Comments
 (0)