I understand. I define my tables like

Table('tablename', metadata, Column('time', DateTime(timezone=True),
nullable=False))

Can I simply replace DateTime with SDateTime and use timezone=True, or
I'd need to add some initializer args for timezone?

Zsolt

On Fri, 25 Jan 2019 at 03:58, Mike Bayer <mike...@zzzcomputing.com> wrote:
>
> On Thu, Jan 24, 2019 at 9:07 PM Zsolt Ero <zsolt....@gmail.com> wrote:
> >
> > 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())
>
> where you define your Table and its column called end_time, don't use
> DateTime, use your custom version of that type.
>
> if you are relying upon reflection, use a column_reflect event
> (https://docs.sqlalchemy.org/en/latest/core/events.html?highlight=column_reflect#sqlalchemy.events.DDLEvents.column_reflect)
> to replace occurrences of DateTime with the custom DateTime object.
>
>
> SQLAlchemy can of course eventually support rendering datetimes as
> literal strings but this becomes a slippery slope where it has to
> support literal rendering for every possible type, and we're then in a
> place where we are reimplementing what the DBAPI already does and I
> don't like to be doing that.   We likely could benefit from a hook
> that works like @compiles here but that's not available at this
> moment.
>
>
>
>
>
> >
> > 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.
>
> --
> 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