On Tue, Sep 11, 2018 at 9:39 AM George Brande <george.bra...@gmail.com> wrote:
>
> Hello.
>
> My angular is using a datepicker to send a date in string format(ex: 
> 2018-09-11) to my flask app to postgres via sqlalchemy.
> In my postgres all rows have a column ef_time of timestamps type.(ex: 
> 2018-09-07 13:24:30.138)
>
>
> @app.route('/orders/<ide>')
> def get_orders(ide):
> session = Session()
> orders_objects = 
> session.query(Orders).filter(Orders.ef_time.like(ide+"%")).all()
> schema = OrdersSchema(many=True)
>    orders = schema.dump(orders_objects)
>
>     session.close()
> return json.dumps(orders.data)
>
> When sending a test, /orders/2018-09-11 my flask app gives me an error: 
> operator does not exist: timestamp without time zone ~~~unknown.
> Line3: Where ord7.ef_time LIKE '2018-09-11%' because, obviously i am seding a 
> string and my ef_time column is of type datestamp without timezone in 
> postgres.
>
> Please give some support, i don't know how to get out this situation. king 
> regards.

I think you need to convert your string to a python datetime object
(eg. using datetime.strptime) and calculate the end date (eg. by using
timedelta), rather than using "LIKE".

Something like this:

  import datetime as dt
  import sqlalchemy as sa

  starttime = dt.datetime.strptime(ide, "%Y-%m-%d")
  endtime = starttime + dt.timedelta(days=1)
  condition = sa.and_(Orders.ef_time >= starttime, Orders.ef_time < endtime)
  orders_objects = session.query(Orders).filter(condition).all()

Hope that helps,

Simon

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to