Skip to content

Commit

Permalink
fixed auto inserter code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nahid5 committed May 16, 2020
1 parent cf41233 commit db4ecd2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions python-auto-insert-to-postgres/inserter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
import psycopg2
from psycopg2.extras import Json, Dictonary
from psycopg2.extras import Json, DictCursor

conn = None
try:
Expand All @@ -10,7 +10,7 @@
conn = psycopg2.connect(connection_str)

# Create cursor that can execute queries
cursor = conn.cursor(cursor_factor=DictCursor)
cursor = conn.cursor(cursor_factory=DictCursor)

# Example query
cursor.execute("SELECT datname FROM pg_database;")
Expand All @@ -21,11 +21,10 @@
# Get output of the command
rows = cursor.fetchall()

except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")

cursor.close()
conn.close()
print("PostgreSQL connection is closed")

except Exception as error :
print ("Error while connecting to PostgreSQL", error)

0 comments on commit db4ecd2

Please sign in to comment.