mchangun
mchangun

Reputation: 10362

SQLAchemy error when selecting specific columns from table

I am trying to select specific columns in SQLAlchemy:

from sqlalchemy import create_engine, MetaData, Table    

engine = create_engine('sqlite:///client.db')
metadata = MetaData(bind=engine)

lc = Table('lc', metadata, autoload=True)

cached = lc.select([lc.c.start, lc.c.end]).execute()

I am getting this error when I try and run the code above:

    "SQL expression object or string expected."
sqlalchemy.exc.ArgumentError: SQL expression object or string expected.

What am I doing wrong?

Upvotes: 1

Views: 7750

Answers (1)

Tasos Vogiatzoglou
Tasos Vogiatzoglou

Reputation: 2453

Table.select accepts only a where clause. For specific columns you should use sqlalchemy.sql.expression.select

from sqlalchemy import select

q = select((lc.c.start, lc.c.end), lc.c.start==<date>)

Upvotes: 2

Related Questions