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

Don't know how to represent mysql type of <table>.<column> (timestamp) #6

Closed
denji opened this issue Aug 8, 2015 · 10 comments
Closed

Comments

@denji
Copy link

denji commented Aug 8, 2015

Seems to be a problem with the work of the timestamp data type:

DROP TABLE IF EXISTS `ts_bug`;
CREATE TABLE `ts_bug` (
    `ids` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `tm` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`ids`)
);
INSERT INTO `ts_bug` (tm) VALUES (CURRENT_TIMESTAMP);
$ ks --from "mysql://denji@localhost/db1" --to "postgresql://denji@localhost/db1"

> Don't know how to represent mysql type of ts_bug.tm (timestamp)

Types formats Conversion: mysql2pgsql/lib/postgres_writer.py

MySQL PostgreSQL
date date
datetime timestamp without time zone
time time without time zone
timestamp timestamp without time zone
mysqlcompat (SQL functions, easing migration)
@willbryant
Copy link
Owner

So we have two ways we could represent this. One option is to add a mysql-specific type and to map it to the existing type on postgresql. The other is to treat this as a datetime column with a special default.

Is the CURRENT_TIMESTAMP default the only reason you are using the timestamp type?

@denji
Copy link
Author

denji commented Sep 10, 2016

Here are some details of the conversion MySQL to PostgreSQL NULL:

  • mysql::timestamp (YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYMMDDHHMM, YYYYMMDD, YYMMDD, YYMM, YY)
  • mysql::datetime (0000-00-00 00:00:00)

We need to transform the 'allballs'::time or just '00:00:00'::time, '-infinity'::timestamp.
Transformation back to MySQL not yet decided, but there can be problems with strict-mode in MySQL 5.6.6+.

@willbryant
Copy link
Owner

So we can turn the mysql special cases into postgresql default value functions. I agree we should use -infinity for the 0000-00-00 00:00:00 time.

What about going the other way? Currently we have no default value function conversion (ie. from mysql to postgresql syntax or vice versa), so maybe we would need to add this for some special cases that kitchen sync itself produces.

@xrewndel
Copy link

xrewndel commented Jan 9, 2017

I have this error too. Any plans to fix this? Or workarounds?

@willbryant
Copy link
Owner

@xrewndel is the CURRENT_TIMESTAMP default the only reason you are using the timestamp type?

@xrewndel
Copy link

xrewndel commented Jan 11, 2017

@willbryant I don't know. I just want to sync mysql to postgres every 5 min. That is my task. I'm looking for simple solutions and don't want to use Talend or smth like this, cause its over-engineering in my particular case.

@willbryant
Copy link
Owner

The issue is that postgresql doesn't have a TIMESTAMP type, so we're trying to decide what it should be mapped to.

We can use a default value function to make inserts into the postgresql table populate the TIMESTAMP column, simulating the mysql behavior.

But as far as I'm aware there's no column setting that can make postgresql reset the timestamp column every time the row is updated, which we'd need to simulate the mysql update behavior. I think you'd have to write a trigger function.

What behavior are you expecting when it gets converted to a postgresql schema?

@damirm
Copy link

damirm commented Jun 8, 2017

Have the same problem.
I think that mysql timestamp should converts to postgres timestamp without time zone

@willbryant
Copy link
Owner

Cool. What about the defaults stuff in my preceding comment?

willbryant added a commit that referenced this issue Jun 20, 2017
… parsing now() back to CURRENT_TIMESTAMP for postgresql so that it can round-trip. work towards #6.

NB. mysql does not support other expressions for column defaults; mariadb 10.2 does, although there seems to be no way to distinguish `CURRENT_TIMESTAMP` from `'CURRENT_TIMESTAMP'` in INFORMATION_SCHEMA.COLUMNS or SHOW FULL FIELDS, so recognising the function definition may be impossible for string column types, which makes me reluctant to implement it yet.  filed as MDEV-13132.
willbryant added a commit that referenced this issue Jun 20, 2017
…ial cases with mysql's timestamp type when we implement issue #6
willbryant added a commit that referenced this issue Jun 21, 2017
… its unique 'on update current_timestamp' behavior
@willbryant
Copy link
Owner

I think version 0.59 has enough that most of you should be able to use it. The special behavior of the column type is mostly supported, except for ON UPDATE CURRENT_TIMESTAMP which has no equivalent in PostgreSQL, and the special values.

Please open new issues for any remaining blockers you find.

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

4 participants