0

I have a table say CATEGORY, and one of its column is CATEGORY_NAME. I want to query all the category_names from the table.

In SQL I would do-

SELECT CATEGORY_NAME FROM CATEGORY;

How can I do this in flask-sqlalchemy?

My model is:

class Category(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    category_name = db.Column(db.String(64), index=True, unique=True)

I read we can do this with with_entities, but it didn't work.

1 Answer 1

2

It worked this way with with_entities:

cat_names = Category.query.with_entities(Category.category_name).all()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.