pgloader/reformat/mysql.py
dim 9b9ef1cc05 pgloader can now reformat data on-the-fly, using modules in reformat package,
dynamically loading them as they're found in the configuration.

Some User-Defined Columns bugfixes too.
2007-11-20 11:54:07 +00:00

25 lines
676 B
Python

# Author: Dimitri Fontaine <dim@tapoueh.org>
#
# pgloader mysql reformating module
#
from pgloader.tools import PGLoader_Error
def timestamp(reject, input):
""" Reformat str as a PostgreSQL timestamp
MySQL timestamps are like: 20041002152952
We want instead this input: 2004-10-02 15:29:52
"""
if len(input) != 14:
e = "MySQL timestamp reformat input too short: %s" % input
raise PGLoader_Error, e
year = input[0:4]
month = input[4:6]
day = input[6:8]
hour = input[8:10]
minute = input[10:12]
seconds = input[12:14]
return '%s-%s-%s %s:%s:%s' % (year, month, day, hour, month, seconds)