'Fetching specific date from MySQL in FastAPI
I want to fetch a date from mysql workbench according to a certain id (msisdn). But I don't know how to do it with SQLAlchemy. msisdn is the primary key.
Should emulate this query:
SELECT
last_port
FROM
`realtime-backend`.portabilidad
WHERE
last_port='2020-04-23 6:00:00' AND
msisdn='56977095634'
Models:
class PortabilidadInfo(Base):
__tablename__ = "portabilidad"
msisdn = Column(Integer, primary_key=True)
operator_id = Column(Integer, nullable=True)
last_port = Column(Date, default=datetime.now(), nullable=True)
Code:
portabilidad_msisdn = '56977095634'
fecha_csv = '2020-04-23 6:00:00'
date_info = session.query(PortabilidadInfo).filter(PortabilidadInfo.last_port == fecha_csv).get(portabilidad_msisdn)
print("FECHA BDD OBJ: ", date_info, type(date_info))
But I get an error saying this: Query.get() being called on a Query with existing criterion.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
