1

Prelude:
Python version: 2.7.9
Pygresql version: 4.0

Problem:
I am trying to check if a sub string exists within a pgqueryobject using python.

Basically I have this in terms of code:

import pg
con = pg.connect(...)
q = con.query(...)

Where q is a pgqueryobject returned from the con.query(...)

Calling print(q) prints the entire table however converting q to a string such as:

string = str(q)
print(string)

Prints "<pg query result>".

I am trying to see if table has now instances (rows) which I planned on doing by converting the table to a string and searching for "0 rows" but I can't seem to figure out how to convert it to a string.

Is there I way I can go about doing this?

2
  • You can most likely accomplish this by saving the output of q.getresult() into a variable and then casting it into a string. pygresql.org/contents/pg/query.html#pg.Query.getresult Commented Aug 3, 2017 at 23:21
  • Glad that helped! Commented Aug 4, 2017 at 13:24

1 Answer 1

1

You can most likely accomplish this by saving the output of q.getresult() into a variable and then casting it into a string.

http://www.pygresql.org/contents/pg/query.html#pg.Query.getresult

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.