I have the following code
from sqlalchemy import *
from sqlalchemy.orm import *
engine = create_engine("postgresql+psycopg2://test:password@localhost/test")
Session = sessionmaker(bind=engine)
session = Session()
metadata = MetaData()
metadata.bind = engine
table = Table('test_table', metadata, autoload = True)
a = session.query(table).filter(table.c.id.in_['1', '2'])
This is the error that is encountered.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'instancemethod' object is unsubscriptable
I am sure that it is something i am doing wrong because I am new to python. Thank you in advance (I am pretty sure it is a rookie mistake)
ColumnOperators.in_ is a function, and therefore must be called. Following should work: