In [9]:
!pip install --upgrade pip
!pip install psycopg2
!pip install psycopg2-binary
In [ ]:
import psycopg2
try:
connect_str = "dbname='basic_db' user='gpadmin' host='gpdbsne' " + \
"password='pivotal'"
# use our connection values to establish a connection
conn = psycopg2.connect(connect_str)
# create a psycopg2 cursor that can execute queries
cursor = conn.cursor()
# create a new table with a single column called "name"
cursor.execute("""CREATE TABLE tutorials (name char(40));""")
# run a SELECT statement - no data in there, but we can try it
cursor.execute("""SELECT * from tutorials""")
rows = cursor.fetchall()
print(rows)
except Exception as e:
print("Uh oh, can't connect. Invalid dbname, user or password?")
print(e)
In [ ]: