implement per-dialect datetime representations, not just strsqlcompiler
See original GitHub issueWhen I try to compile a query with datetime parameters using literal_binds
, e.g.:
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, DateTime
from sqlalchemy.orm import sessionmaker
from datetime import datetime
engine = create_engine('sqlite:///:memory:', echo=True)
Base = declarative_base()
class M(Base):
__tablename__ = 'M'
d = Column(DateTime, primary_key=True)
Session = sessionmaker()
print(Session().query(M).filter(
M.d < datetime.now()
).statement.compile(
compile_kwargs={'literal_binds': True}
))
the engine gives me the following error
NotImplementedError: Don't know how to literal-quote value datetime.datetime(2019, 12, 25, 14, 26, 42, 756674)
There probably should be a default representation for datetimes as an iso-formatted string in single quotes.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
datetime — Basic date and time types — Python 3.11.1 ...
Source code: Lib/datetime.py The datetime module supplies classes for manipulating dates and times. While date and time arithmetic is supported, the focus ...
Read more >Datetime values - IBM
The datetime data types are DATE, TIME, and TIMESTAMP. Although datetime values can be ... The internal representation of a date is a...
Read more >Custom date and time format strings | Microsoft Learn
Learn to use custom date and time format strings to convert DateTime or DateTimeOffset values into text representations, or to parse strings ...
Read more >PHP date() format when inserting into datetime in MySQL
The problem is that you're using 'M' and 'D' , which are a textual representations, MySQL is expecting a numeric representation of the...
Read more >Datetime Patterns for Formatting and Parsing - Apache Spark
CSV/JSON datasources use the pattern string for parsing and formatting datetime content. Datetime functions related to convert StringType to/from DateType or ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think that we can reopen this, since at the moment we just implemented a default representation when literally compile without a dialect. These is still no implementation for specific dialects, other that sqlite
Mike Bayer has proposed a fix for this issue in the main branch:
implement iso date literals for all backends https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3744