summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-06-29 15:45:20 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-06-29 15:45:20 -0400
commit30f8843e97a49121323a4f75d9341f77c9935312 (patch)
tree7ccc6d1255f7e28499848c29f64e5fc73688fa7b /lib
parent808d7ca8d231fb5d3ce4ccc2ca9a74f5767e9154 (diff)
downloadsqlalchemy-30f8843e97a49121323a4f75d9341f77c9935312.tar.gz
Include DATETIME / DateTime with the MySQL TIMESTAMP examples
To eliminate any remaining confusion, clarify that DATETIME (as well as DateTime) and TIMESTAMP are treated similarly with the MySQL dialect regarding ON UPDATE. Change-Id: I222522440706902d5d2d11e670e76f16000438e0 References: #5427
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index e64bd97cc..d3d7a8cce 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -670,8 +670,8 @@ with the ``unique=True`` setting present in the :attr:`_schema.Table.indexes`
collection.
-TIMESTAMP issues
------------------
+TIMESTAMP / DATETIME issues
+---------------------------
.. _mysql_timestamp_onupdate:
@@ -690,7 +690,8 @@ MySQL 5.6 introduced a new flag `explicit_defaults_for_timestamp
#sysvar_explicit_defaults_for_timestamp>`_ which disables the above behavior,
and in MySQL 8 this flag defaults to true, meaning in order to get a MySQL
"on update timestamp" without changing this flag, the above DDL must be
-rendered explicitly.
+rendered explicitly. Additionally, the same DDL is valid for use of the
+``DATETIME`` datatype as well.
SQLAlchemy's MySQL dialect does not yet have an option to generate
MySQL's "ON UPDATE CURRENT_TIMESTAMP" clause, noting that this is not a general
@@ -718,6 +719,24 @@ parameter and pass a textual clause that also includes the ON UPDATE clause::
)
)
+The same instructions apply to use of the :class:`_types.DateTime` and
+:class:`_types.DATETIME` datatypes::
+
+ from sqlalchemy import DateTime
+
+ mytable = Table(
+ "mytable",
+ metadata,
+ Column('id', Integer, primary_key=True),
+ Column('data', String(50)),
+ Column(
+ 'last_updated',
+ DateTime,
+ server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
+ )
+ )
+
+
Even though the :paramref:`_schema.Column.server_onupdate` feature does not
generate this DDL, it still may be desirable to signal to the ORM that this
updated value should be fetched. This syntax looks like the following::