import psycopg2
import os
try:
connection = psycopg2.connect(user=os.environ["POSTGRESSQL_TEST_USER"],
password=os.environ["POSTGRESSQL_TEST_PASSWORD"],
host=os.environ["POSTGRESSQL_TEST_HOST"],
port=os.environ["POSTGRESSQL_TEST_PORT"],
database=os.environ["POSTGRESSQL_TEST_DATABASE"])
with connection.cursor() as cursor:
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record)
except (Exception, psycopg2.Error) as error:
print ("Error while connecting to PostgreSQL", error)
You are connected to - ('PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit',)
import pandas as pd
query = SELECT * FROM covid_19_data LIMIT 100;
df = pd.io.sql.read_sql_query(query, connection)
df
SyntaxError: invalid syntax (<ipython-input-6-ed2e4f884510>, line 3)
!ls /datasets/s3-example
1.txt example.txt kek.txt tst.txt
SQL
Saved to variable
<none>input