Do I understand it right that there is no approach which could print a
query without the need to modify it, if it contains datetimes?

If so, how can I turn a where statement into something which is
printable using SDateTime?

.where(trips.c.end_time >= datetime.datetime.now())

Zsolt

On Mon, 21 Jan 2019 at 19:22, Mike Bayer <mike...@zzzcomputing.com> wrote:
>
> On Mon, Jan 21, 2019 at 12:23 PM Zsolt Ero <zsolt....@gmail.com> wrote:
> >
> > Thanks it works perfectly, even with datetimes!
> >
> > Can I do something similar to make
> >
> > stmt.compile(dialect=postgresql.dialect(),
> > compile_kwargs={"literal_binds": True})
> >
> > compatible with datetime? Or maybe not this, but I'm looking for a way
> > to print a statement which I could copy and paste into psql console.
>
> that's what literal_binds is for but it doesn't support formatting
> every kind of type directly, so I assume you're getting an error
> message, at the moment the literal_processor can't be injected so you
> have to use a new type:
>
> from sqlalchemy import *
> from sqlalchemy.dialects import postgresql
> from sqlalchemy.ext.compiler import compiles
> import datetime
>
>
> class SDateTime(TypeDecorator):
>     impl = DateTime
>
>     def literal_processor(self, dialect):
>         return lambda value: str(value)
>
>
> print(
>     select([column("q", SDateTime) == datetime.datetime.now()]).compile(
>         dialect=postgresql.dialect(), compile_kwargs=dict(literal_binds=True)
>     )
> )
>
>
>
>
> >
> > Zsolt
> >
> > --
> > 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.
>
> --
> 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 a topic in the Google 
> Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/sqlalchemy/KXnv1_9B_Fw/unsubscribe.
> To unsubscribe from this group and all its topics, 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.

-- 
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