question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

implement per-dialect datetime representations, not just strsqlcompiler

See original GitHub issue

When 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:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
CaselITcommented, Mar 30, 2020

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

0reactions
sqla-testercommented, Mar 28, 2022

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

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found