sqlalchemy returns list of tuples and not just a value for a simple "select...where" query

Viewed 614

I know some SQL from using PHP but SQLAlchemy I am stumbling on. My first query:

engine.table_names()

from sqlalchemy import select, Table, Column, String,\
    MetaData
sql = "select id from user where email = 'omg@gmail.com'"
conn=engine.connect()
res_proxy = conn.execute(sql)
res = res_proxy.fetchall()
user_id = res[0][0]
print(res[0][0])
row = res[0]
print(row.keys())
print(res)

This outputs

1
['id']
[(1,)]

My second query

#query meals table and get highest meal number
sql2 = "select meal_id from user_meals where user_id='user_id'"
res_proxy = conn.execute(sql2)
res = res_proxy.fetchall()
print(res)

Outputs

[]

It's an empty table so that is correct. Why are the return values lists and in the first query a list of tuple?

0 Answers
Related