I am using Postgres and SQLAlchemy as the ORM.
I have this query and I cannot seem to convert it to SQLAlchemy.
select to_timestamp(create_time)::date from inventory_item
create_time column is epoch time. The result of this query is this:
2019-02-24
Here's what I tried so far
InventoryItem.query.with_entities(db.func.to_timestamp(InventoryItem.create_time)).filter_by(inventory_id="1810092340894EA").first()
Result from this query is this.
(datetime.datetime(2018, 10, 9, 23, 40, 17, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=480, name=None)),)
I only want the date and exclude the time.
I tried the tagged duplicate answer, but it is not working.
InventoryItem.query.with_entities(cast(InventoryItem.create_time, Date)).filter_by(order_id="1810092340894EA").first()
Result:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) cannot cast type integer to date