2016-01-22 14 views
5

Sono nuovo di Postgres e ho lavorato su Mysql per la tranquillità a volte. Devo migrare il contenuto dalla tabella Mysql alla tabella Postgres.Come convertire un timestamp Mysql in formato sysdate (6) (con millisecondi)?

tavolo mio Postgres è come questo:

   Column    |   Type    |           Modifiers            
--------------------------------+-----------------------------+------------------------------------------------------------------------------------------------ 
id        | integer      | 
created_at      | timestamp without time zone | not null default timezone('UTC'::text, now()) 
updated_at      | timestamp without time zone | not null default timezone('UTC'::text, now()) 
key_classification    | character varying(2000)  | not null 

sto inserendo created_at e updated_at valore dalla tabella di MySQL, che è in forma "2014/09/04 23:40:14".

quando inserisco una riga nella mia tabella postgres la data/ora di default è nel formato "2016-01-22 17: 44: 53.342757" che include millisecondo nel timestamp.

Ora ho bisogno di aggiungere il millisecondo al formato timestamp mysql per abbinare il formato della tabella Postgres.

Si prega di contribuire ad aggiungere il millisecondo nel timestamp.

Grazie in anticipo!

+3

Forse avete bisogno di leggere [timestamp con un presicion millisecondo come salvare l'a mysql] (http://stackoverflow.com/questions/26299149/timestamp-with-a-millisecond -precisione-how-to-save-them-in-mysql) – eusoj

+0

hai bisogno di questa precisione in mysql, o pensi di averne bisogno per la migrazione? postgresql accetterà volentieri anche timbri più brevi, anche "2016-01-22" come abbreviazione di "2016-01-22 00: 00: 00.000000" – knitti

risposta

0

Mattino Arunraj Spero che questo aiuti?

Io corro Mysql/MariaDB

MariaDB [(none)]> SHOW VARIABLES LIKE "%version%"; 
+-------------------------+-----------------+ 
| Variable_name   | Value   | 
+-------------------------+-----------------+ 
| innodb_version   | 5.6.25-73.1  | 
| protocol_version  | 10    | 
| slave_type_conversions |     | 
| version     | 10.0.21-MariaDB | 
| version_comment   | MariaDB Server | 
| version_compile_machine | x86_64   | 
| version_compile_os  | Linux   | 
| version_malloc_library | system   | 
+-------------------------+-----------------+ 
8 rows in set (0.00 sec) 

E io sto riferimento 11.3.6 Fractional Seconds in Time Values che è la versione di MySQL 5.7

per eseguire l'esempio

As mysql Admin 
mysql -u USERNAME -p 

CREATE USER 'test'@'localhost' IDENTIFIED BY 'test'; 

CREATE DATABASE test; 

GRANT ALL ON test.* TO 'test'@'localhost'; 

Chiudere e quindi accedere come test

mysql -u test -p 

La password è prova

Poi

CREATE TABLE test.td6(ts6 timestamp(6)); 

INSERT INTO test.td6 VALUES ('2016-01-22 17:44:53.342757'); 

Il valore introdotto non e 'il formato di data e ora che si voleva inserire in mysql. Example Results Ref msql 5.7

Tutto il meglio

Problemi correlati