0

I understand this question has been asked many times but in my case I can't find a way to simply resolve it. I have a very basic fetchone() query as below:

conn = psycopg2.connect(
    host=postgres_host,
    database=postgres_database,
    user=postgres_user,
    password=postgres_password)
    
cur = conn.cursor()
cur.execute("SELECT * FROM videos WHERE status = %s" , (0))
result = cur.fetchone()
print(result[0])
exit

I am still getting the result which is the ID of my row cursor returning but right after print statement I get "'int' object does not support indexing"

I've been through Stackoverflow for an hour and tried all suggestions but can't find the right answer. Not sure using list is the best approach, as I see it returning a tuple is a very basic query. Any advice? Thanks

JJ The Second
  • 77
  • 3
  • 11
  • See [this answer](https://stackoverflow.com/a/64952928/5320906) to the linked duplicate. – snakecharmerb Oct 01 '22 at 21:46
  • `result` should be the entire table row as selected by `*`. Assuming `id` is the first field in the row then `result[0]` should be `id` and won't result in the indexing error. So either the query is not as you have it in the question or `result[0]` is referring to something other then the output of `cur.fetchone()`. To your question add `print(result)`. – Adrian Klaver Oct 01 '22 at 22:12

0 Answers0