def sql_datetime_literal(dt: DateTimeLikeType,
                         subsecond: bool = False) -> str:
    """
    Transforms a Python object that is of duck type ``datetime.datetime`` into
    an ANSI SQL literal string, like ``'2000-12-31 23:59:59'``, or if
    ``subsecond=True``, into the (non-ANSI) format
    ``'2000-12-31 23:59:59.123456'`` or similar.
    """
    # ANSI SQL: http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt
    # <timestamp string>
    # ... the subsecond part is non-ANSI
    fmt = "'%Y-%m-%d %H:%M:%S{}'".format(".%f" if subsecond else "")
    return dt.strftime(fmt)
def sql_datetime_literal ( dt : DateTimeLikeType , subsecond : bool = False ) -> str : fmt = "'%Y-%m-%d %H:%M:%S{}'" . format ( ".%f" if subsecond else "" ) return dt . strftime ( fmt )
Transforms a Python object that is of duck type ``datetime.datetime`` into
    an ANSI SQL literal string, like ``'2000-12-31 23:59:59'``, or if
    ``subsecond=True``, into the (non-ANSI) format
    ``'2000-12-31 23:59:59.123456'`` or similar.