The last bit I am struggling with on Project1 is posting a rating and review. I continually get

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'RowProxy'
[SQL: INSERT INTO reviews (rating, review, book_id, user_id) VALUES (%(rating)s, %(review)s, %(book_id)s, %(user_id)s)]
[parameters: {'rating': 4, 'review': 'great', 'book_id': 3, 'user_id': (13,)}]

The traceback leads to this line:

sql_string = "INSERT INTO reviews (rating, review, book_id, user_id)\
         VALUES (:rating, :review, :book_id, :user_id)"
db.execute(sql_string, {"rating": rating, "review": review, "book_id": bookid, "user_id": currentuser})

My fetching code looks like this:

row = db.execute("SELECT id FROM books2 WHERE isbn = :isbn", {"isbn":isbn}).fetchone()
bookid = row[0]
currentuser = session["user_id"]
review = request.form.get("review")
rating = request.form.get("rating")

I was under the impression that it is necessary to .fetchone()[0] to ensure a tuple (my user_id shows up as 'user_id': (13,), whereas the other values aren't like that. Can the rating and review values be changed to a (x, ) form? Or is it the user_id that's triggering it, since it's the only different one?

Other SQL commands in the rest of my program do not seem to trigger this error, and I don't see any immediate difference, as I'm using .fetchone()[0] for the rest, as well.

1 Answer 1


In case anyone has this problem in the future:

The big problem was fixed by ..."user_id": currentuser[0]}) where currentuser=session["user_id"] There were a handful of smaller problems after that, but fixed relatively quickly, and irrelevant.

  • How do you apply this solution on a array??
    – stormcloak
    Commented Jan 20, 2021 at 4:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .