Home > Software design >  sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Row'
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Row'

Time:04-17

I created a database with 3 tables using PostgreSQL and flask-sqlalchemy. I am querying 3 tables to get only their ids then I check their ids to see if there's any similar one then add the similar one to the third table but anytime i run it i get this error

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Row' [SQL: INSERT INTO login (student_id, name, timestamp) VALUES (%(student_id)s, %(name)s, %(timestamp)s)] [parameters: {'student_id': (1234567,), 'name': None, 'timestamp': datetime.datetime(2022, 4, 16, 21, 10, 53, 30512)}]

@app.route('/')
def check():
id = Esp32.query.with_entities(Esp32.student_id).all()
students = Student.query.with_entities(Student.student_id).all()
logins = Login.query.with_entities(Login.student_id).all()
for ids in id:   
    if ids in students and ids not in logins:
        new = Login(student_id= ids)
        db.session.add(new)
        db.session.commit()
return render_template('check.html', newlog = new)

please could someone tell me what this error means and why I am getting it

CodePudding user response:

id is a query result. ids is a query row. To get one value from that row, you need to tell it which column (even if there is only one column): ids['student_id]'.

  • Related