0

I am trying to read data directly from Postgres to my python environment with the below:

import psycopg2 as pg
import pandas.io.sql as psql
conn = pg.connect(database="abcd",user="postgres", password="xxxx")
df = pd.read_sql('SELECT * "xyz"', conn)
df.head()

But I get the below error when reading:

DatabaseError: Execution failed on sql 'SELECT * "xyz"': syntax error at or near ""xyz"" LINE 1: SELECT * "trans"

0

2 Answers 2

3

You didn't specify important keyword "FROM":

df = pd.read_sql('SELECT * "xyz"', conn)

so the right one is:

df = pd.read_sql('SELECT * FROM "xyz"', conn)
2

You did not define anything as pd. So just change pd to psql, and add the table name:

df = psql.read_sql('SELECT * FROM tablename', conn)

Not the answer you're looking for? Browse other questions tagged or ask your own question.