A
A
Alexander Semenenko2018-03-23 12:24:23
Python
Alexander Semenenko, 2018-03-23 12:24:23

Why does an error occur when running python3.6 with postgresql?

Good afternoon, I'm just starting to learn the work of postgresql and indeed sql. I know a little python.
I am using the postgresql.driver module. By the way, I have not yet understood why there are a lot of them PyGreSQL, psycopg2 and which one is better to use. If you tell me what is the difference, and which is better to use, I will be grateful.
I connect to the database like this:

import postgresql.driver as pg
db = pg.connect(user='xxxx', password='xxxx', host='localhost', database='english', port=5432)

So far I can't figure this out. If I write like this, then everything works:
for name in db.prepare("SELECT russian FROM english WHERE number = 1"):
    print(name)
db.close()

If I write like this, I get an error:
print (db.prepare("SELECT russian FROM english WHERE number = 1"))

or:
word = db.prepare("SELECT russian FROM english WHERE number = 1")
print (word)

Error:
postgresql.driver.pq3.Statement[pq://xxx:***@localhost:5432/english] prepared

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-03-23
@semenenko88

It's not an error, it's a textual representation of a prepared query . In the first example, you loop through it, and in the second and third, you print it out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question