Aditya J
Aditya J

Reputation: 31

Unable to fetch rows from PostGresSQL table

I'm trying to fetch data from a table in the PostGreSQL database. I'm able to query the results using PostGreSQL but when I try to do so with Python using psycopg2 module, it doesn't return anything. The curse object returned is of type "None" and is non iterable.

Here's my code:

import psycopg2 as p
con = p.connect(database="Scheduling", user="postgres", password="test", host="127.0.0.1", 
port="5432")
cur = con.cursor()
df = cur.execute(''' SELECT * FROM  public."HOME" ''').fetchall()
print(type(df))

Here's the error message: Traceback (most recent call last): File "C:/Users/adi.jakka/PycharmProjects/Flask/TEST.PY", line 4, in df = cur.execute(''' SELECT * FROM public."HOME" ''').fetchall() AttributeError: 'NoneType' object has no attribute 'fetchall'

Process finished with exit code 1

Upvotes: 0

Views: 740

Answers (1)

Prakash
Prakash

Reputation: 192

This should work:

import psycopg2 as p
con = p.connect(database="Scheduling", user="postgres", password="test", host="127.0.0.1", 
port="5432")
cur = con.cursor()
cur.execute(''' SELECT * FROM  public."HOME" ''')
df = cur.fetchall()
print(df)

Upvotes: 2

Related Questions