Kay
Kay

Reputation: 1485

sqlalchemy how to get list of data instead of list of sqlalchemy.util._collections.result

I have a table of file information in my DB I am trying to query and return the file_path column of the result as list of string.

My code looks like below

path_found = session.query(db.file_table.path).filter([filters]).all()

It returns a list of sqlalchemy.util._collections.result instead of list of string.

Is there any way to get the query result as a list of string?

Upvotes: 2

Views: 3017

Answers (2)

Awais Kaleem
Awais Kaleem

Reputation: 9

Here is the Example Code:

query = session.query(Region.name).all()

query = map(lambda t: t[0], query)
query = list(query)

print(query)

Upvotes: 1

Prime Reaper
Prime Reaper

Reputation: 186

result = [str(path) for path in path_found]

Upvotes: 1

Related Questions