--- mysql2pgsql 2000/04/25 14:02:47 1.4 +++ mysql2pgsql 2000/10/24 11:40:45 1.5 @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl +#!/usr/local/bin/perl -w # MySQL to PostgreSQL dump file converter # @@ -86,6 +86,8 @@ # blob -> text s/\w*blob/text/gi; + # tinytext -> text + s/tinytext/text/gi; # char -> varchar # PostgreSQL would otherwise pad with spaces as opposed @@ -97,16 +99,25 @@ s/date default '[^']+'/datetime/i; s/time default '[^']+'/datetime/i; - # change not null datetime filend to null valid ones - # (to support remapping of "zaro time" to null + # change not null datetime field to null valid ones + # (to support remapping of "zero time" to null s/datetime not null/datetime/i; + # nuke size of timestamp + s/timestamp\([^)]*\)/timestamp/i; + + # double -> float8 + s/double\([^)]*\)/float8/i; + # add unique to definition of type (MySQL separates this) if (/unique \w+ \((\w+)\)/i) { - $sql=~s/($1)([^,]+)/$1$2 unique/gi; + $sql=~s/($1)([^,]+)/$1$2 unique/i; next; } + # quote column names + s/(^\s*)(\S+)(\s*)/$1"$2"$3/gi if (!/key/i); + } else { # not inside create table #---- fix data in inserted data: (from MS world) @@ -123,6 +134,7 @@ s/'0000-00-00 00:00:00'/null/gi; s/'0000-00-00'/null/gi; s/'00:00:00'/null/gi; + s/([12]\d\d\d)([01]\d)([0-3]\d)([0-2]\d)([0-6]\d)([0-6]\d)/'$1-$2-$3 $4:$5:$6'/; } $sql.="$_";