I'm trying to get all the rows in a table, but only one column. The model looks like this:
class Person:
id= db.Column(db.String(11), primary_key=True, nullable=False)
name = db.Column(db.String(255), nullable=False)
city = db.Column(db.String(255), nullable=False)
I want to get the name
column ONLY but I can't find anything on how to do this.
I've tried stuff like:
Person.query.get(person.name)
The SQLAlchemy documentation doesn't help at all.
You need to use with_entities
to specify the column that you want to SELECT
:
Person.query.with_entities(Person.name).all()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With