Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql8.0, miss on-update-current-timestamp trigger when the column has default value #1560

Open
optionals opened this issue Feb 21, 2024 · 0 comments

Comments

@optionals
Copy link

mysql

CREATE TABLE `onupdate` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `patient_id` varchar(50) NOT NULL,
  `update_date1` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `update_date2` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE current_timestamp(),
  `update_date3` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  `update_date4` timestamp NULL ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `patient_id` (`patient_id`)
);

then show COLUMNS

SHOW COLUMNS FROM onupdate; 
+--------------+-------------+------+-----+-------------------+-----------------------------------------------+
| Field        | Type        | Null | Key | Default           | Extra                                         |
+--------------+-------------+------+-----+-------------------+-----------------------------------------------+
| id           | int         | NO   | PRI | NULL              | auto_increment                                |
| patient_id   | varchar(50) | NO   | UNI | NULL              |                                               |
| update_date1 | timestamp   | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |
| update_date2 | timestamp   | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |
| update_date3 | timestamp   | YES  |     | NULL              | on update CURRENT_TIMESTAMP                   |
| update_date4 | timestamp   | YES  |     | NULL              | on update CURRENT_TIMESTAMP                   |
+--------------+-------------+------+-----+-------------------+-----------------------------------------------+

pg

loader@/tmp:loader> \df
+--------+--------------------------------------+------------------+---------------------+---------+
| Schema | Name                                 | Result data type | Argument data types | Type    |
|--------+--------------------------------------+------------------+---------------------+---------|
| loader | on_update_current_timestamp_onupdate | trigger          |                     | trigger |
+--------+--------------------------------------+------------------+---------------------+---------+
SELECT 1
Time: 0.092s

Extra

Any additional information that is available about a given column. The value is nonempty in these cases:

  • auto_increment for columns that have the AUTO_INCREMENT attribute.

  • on update CURRENT_TIMESTAMP for TIMESTAMP or DATETIME columns that have the ON UPDATE CURRENT_TIMESTAMP attribute.

  • VIRTUAL GENERATED or STORED GENERATED for generated columns.

  • DEFAULT_GENERATED for columns that have an expression default value.

fix

I add a judgmental condition as a temporary solution

;;; src/sources/mysql/mysql-cast-rules.lisp
(defun normalize-extra (extra)
  "Normalize MySQL strings into pgloader CL keywords for internal processing."
  (cond ((string= "auto_increment" extra)
         :auto-increment)

        ((or (string= extra "on update CURRENT_TIMESTAMP")
             (string= extra "on update current_timestamp()")
             (string= extra "DEFAULT_GENERATED on update CURRENT_TIMESTAMP"))
         :on-update-current-timestamp)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant