Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1037333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:50:25+00:00 2026-05-16T14:50:25+00:00

is it possible to override the default type.DateTime behaviour when using sqlalchemy with raw

  • 0

is it possible to override the default type.DateTime behaviour when using sqlalchemy with raw sql expressions?

for example when using

myconnection.execute(text("select * from mytable where mydate > :mydate), {'mydate': mypythondatetimeobject)}

, i would like to have type.DateTime to automatically strip the TimeZone from the DateTime object.

UPDATE: i found out, that it works by using bindparam and a Typedecorator on the query like this:

class MyType(types.TypeDecorator):
    impl = types.DateTime

    def process_bind_param(self, value, dialect):
        if value is not None:
            return value.replace(tzinfo=None)

session.execute(
    text(myquery, bindparams=[bindparam('mydateparam', 
                                        type_=MyType())]), 
    {'mydateparam':mydate}
)

but i really dont want to use “bindparams” on every query. isnt it possible to simply replace or override the default types.DateTime behaviour somehow?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:50:26+00:00Added an answer on May 16, 2026 at 2:50 pm

    If you used SQL expressions based on Table metadata, then you’d just set your MyType on the appropriate columns. The plain text approach loses some convenience. You could stick your MyType into the sqlalchemy.types.type_map keyed to the datetime class, though this is currently not public API.

    If it were me I’d do:

    def mytext(stmt, params):
        bindparams = []
        for k, v in params:
            if isinstance(v, datetime):
                type_ = MyType()
            else:
                type_ = None
            bindparams.append(bindparam(k, v, type_=type))
        return text(stmt, bindparams=bindparams)
    

    then just use mytext(“select * from table where date=:date”, {‘date’:datetime.today()})

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could put the sessionId (key) and timestamp (value) in… May 16, 2026 at 3:52 pm
  • Editorial Team
    Editorial Team added an answer It depends somewhat on your application and how it is… May 16, 2026 at 3:51 pm
  • Editorial Team
    Editorial Team added an answer Primitives defined locally would be on the stack. However if… May 16, 2026 at 3:51 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I was wondering if anyone knew if it were possible to override the default
My question may duplicate Default implementation for Object.GetHashCode() but I'm asking again because I
Designer: tableName: designers actAs: I18n: fields: [name] columns: id: type: integer(2) unsigned: true primary:
I've got a project where I've just discovered that warning C4244 (possible loss of
I have recently come across a very simple Typed DataTable (without using a .XSD)(I've
I have a list view that is displaying data using the gridview. This list
once again I've got a question. Since I am using Google Web Toolkit (GWT)
Possible Duplicate: Python's use of __new__ and __init__ ? The way I understand it,
I'm trying to override a property in a base class with a different, but
Is it possible to invoke method A.F() from instance of B class except of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.