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