ashok
ashok

Reputation: 1

Errors while joining two tables using sqlalchemy

When I tried to join two tables I got the following error:

sqlalchemy.exc.ObjectNotExecutableError: Not an executable object:
sqlalchemy.sql.selectable.Join at 0x7f31a35b02e8; Join object on
chanel(139851192912136) and Device(139851192912864)

My code is:

import sqlalchemy as db
from sqlalchemy import and_,or_,not_,inspect,text,inspection
engine = db.create_engine("mssql+pymssql://sa:[email protected]/ELNetDB")
Data1 = db.Table("chanel", metadata, autoload=True, autoload_with=engine)
Data2 = db.Table("Device",metadata,autoload = True,autoload_with = engine)
metadata = db.MetaData()
j = Data1.join(Data2,Data1.columns.No == Data2.columns.ID)
print(engine.execute(j))

Upvotes: 0

Views: 944

Answers (1)

Anthony Kong
Anthony Kong

Reputation: 40624

Data1.join(Data2,Data1.columns.No == Data2.columns.ID) is not executable because it is not a query object.

You can try this instead (assuming you want to select every column from Data1):

print( engine.execute(select([Data1]).select_from(j) )

see https://docs.sqlalchemy.org/en/13/core/metadata.html#sqlalchemy.schema.Table.join for reference.

Upvotes: 1

Related Questions