From 13b63d3764f5bd67ef3243ca0ba5c9d4b8b182ab Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 19 Apr 2004 23:18:12 +0000 Subject: [PATCH] Update to my2pg version 1.28, add docs, update URL for newest version. Create diff of custom changes Tom made to the utility for CREATE FUNCTION. This will make moving this utility out of CVS easier. --- contrib/mysql/README | 2 +- contrib/mysql/my2pg.diff | 112 +++++++++++++++++++++++ contrib/mysql/my2pg.html | 193 +++++++++++++++++++++++++++++++++++++++ contrib/mysql/my2pg.pl | 35 +++++-- 4 files changed, 331 insertions(+), 11 deletions(-) create mode 100644 contrib/mysql/my2pg.diff create mode 100755 contrib/mysql/my2pg.html diff --git a/contrib/mysql/README b/contrib/mysql/README index 5511df6c67..953e204d42 100644 --- a/contrib/mysql/README +++ b/contrib/mysql/README @@ -2,7 +2,7 @@ Here are two conversion utilities for MySQL dumps. Use the one you prefer. The most recent version of my2pg.pl can be obtained from: - http://ziet.zhitomir.ua/~fonin/code/ + http://www.omnistarinc.com/~fonin/downloads.php#my2pg Another tool, mysql2pgsql, can be found at: diff --git a/contrib/mysql/my2pg.diff b/contrib/mysql/my2pg.diff new file mode 100644 index 0000000000..7c870b3b27 --- /dev/null +++ b/contrib/mysql/my2pg.diff @@ -0,0 +1,112 @@ +*** /laptop/my2pg.pl Mon Apr 19 18:51:44 2004 +--- my2pg.pl Mon Apr 19 18:59:09 2004 +*************** +*** 38,43 **** +--- 38,50 ---- + # $My2pg: my2pg.pl,v 1.28 2001/12/06 19:32:20 fonin Exp $ + # $Id: my2pg.diff,v 1.1 2004/04/19 23:18:12 momjian Exp $ + ++ # Custom patch ++ # Revision 1.9 2002/08/22 00:01:39 tgl ++ # Add a bunch of pseudo-types to replace the behavior formerly associated ++ # with OPAQUE, as per recent pghackers discussion. I still want to do some ++ # more work on the 'cstring' pseudo-type, but I'm going to commit the bulk ++ # of the changes now before the tree starts shifting under me ... ++ + # + # $Log: my2pg.diff,v $ + # Revision 1.1 2004/04/19 23:18:12 momjian + # Update to my2pg version 1.28, add docs, update URL for newest version. + # + # Create diff of custom changes Tom made to the utility for CREATE + # FUNCTION. + # + # This will make moving this utility out of CVS easier. + # + # Revision 1.28 2002/11/30 12:03:48 fonin +*************** +*** 332,342 **** + print LIBTYPES "\n * Types for table ".uc($table_name); + print LIBTYPES "\n */\n"; + +! $types.="\nCREATE FUNCTION $typename"."_in (opaque) + RETURNS $typename + AS '$libtypename' + LANGUAGE 'c' +! WITH (ISCACHABLE);\n"; + + # creating output function + my $func_out=" +--- 339,349 ---- + print LIBTYPES "\n * Types for table ".uc($table_name); + print LIBTYPES "\n */\n"; + +! $types.="\nCREATE FUNCTION $typename"."_in (cstring) + RETURNS $typename + AS '$libtypename' + LANGUAGE 'c' +! WITH (ISSTRICT, ISCACHABLE);\n"; + + # creating output function + my $func_out=" +*************** +*** 386,396 **** + return (*a>=*b); + }\n"; + +! $types.="\nCREATE FUNCTION $typename"."_out (opaque) +! RETURNS opaque + AS '$libtypename' + LANGUAGE 'c' +! WITH (ISCACHABLE);\n"; + + $types.="\nCREATE TYPE $typename ( + internallength = 2, +--- 393,403 ---- + return (*a>=*b); + }\n"; + +! $types.="\nCREATE FUNCTION $typename"."_out ($typename) +! RETURNS cstring + AS '$libtypename' + LANGUAGE 'c' +! WITH (ISSTRICT, ISCACHABLE);\n"; + + $types.="\nCREATE TYPE $typename ( + internallength = 2, +*************** +*** 532,538 **** + print LIBTYPES "\n * Types for table ".uc($table_name); + print LIBTYPES "\n */\n"; + +! $types.="\nCREATE FUNCTION $typename"."_in (opaque) + RETURNS $typename + AS '$libtypename' + LANGUAGE 'c';\n"; +--- 539,545 ---- + print LIBTYPES "\n * Types for table ".uc($table_name); + print LIBTYPES "\n */\n"; + +! $types.="\nCREATE FUNCTION $typename"."_in (cstring) + RETURNS $typename + AS '$libtypename' + LANGUAGE 'c';\n"; +*************** +*** 584,591 **** + + \n"; + +! $types.="\nCREATE FUNCTION $typename"."_out (opaque) +! RETURNS opaque + AS '$libtypename' + LANGUAGE 'c';\n"; + +--- 591,598 ---- + + \n"; + +! $types.="\nCREATE FUNCTION $typename"."_out ($typename) +! RETURNS cstring + AS '$libtypename' + LANGUAGE 'c';\n"; + diff --git a/contrib/mysql/my2pg.html b/contrib/mysql/my2pg.html new file mode 100755 index 0000000000..13704249aa --- /dev/null +++ b/contrib/mysql/my2pg.html @@ -0,0 +1,193 @@ + + +my2pg - MySQL -> PostgreSQL dump conversion utility. + + + + + + + + + + + +
+

+

NAME

+

my2pg - MySQL -> PostgreSQL dump conversion utility.

+

+


+

SYNTAX

+
+        mysqldump db | ./my2pg.pl [-nds] > pgsqldump.sql
+        vi libtypes.c
+        make
+        psql database < pgsqldump.txt
+where
+
+
pgsqldump.sql
+
+- file suitable for loading into PostgreSQL. +

+
libtypes.c
+
+- C source for emulated MySQL types (ENUM, SET) generated by my2pg +

+

+


+

OVERVIEW

+

my2pg utility attempts to convert MySQL database dump to Postgres's one. +my2pg performs such conversions:

+ +

It encloses dump in transaction block to prevent single errors +during data load.

+

+


+

COMMAND-LINE OPTIONS

+

My2pg takes the following command-line options:

+
+
-n
+
+Convert *CHAR DEFAULT '' NOT NULL types to *CHAR NULL. +Postgres can't load empty '' strings in NOT NULL fields. +

+
-d
+
+Add double quotes around table and column names +

+
-h
+
+Show usage banner. +

+
-s
+
+Do not attempt to convert data. Currently my2pg only tries to convert +date and time data. +

+

+


+

SIDE EFFECTS

+ +

+


+

BUGS

+

Known bugs are:

+ +

+


+

AUTHORS

+

(c) 2000-2002 Maxim V. Rudensky (fonin@ziet.zhitomir.ua) (developer, maintainer)

+

(c) 2000 Valentine V. Danilchuk (valdan@ziet.zhitomir.ua) (original script)

+

+


+

CREDITS

+

Great thanks to all those people who provided feedback and make development +of this tool easier.

+

Jeff Waugh <jaw@ic.net>

+

Joakim Lemström <jocke@bytewize.com> || <buddyh19@hotmail.com>

+

Yunliang Yu <yu@math.duke.edu>

+

Brad Hilton <bhilton@vpop.net>

+

If you are not listed here please write to me.

+

+


+

LICENSE

+

BSD

+ + + + diff --git a/contrib/mysql/my2pg.pl b/contrib/mysql/my2pg.pl index b24e09d1dc..218a6a65ce 100755 --- a/contrib/mysql/my2pg.pl +++ b/contrib/mysql/my2pg.pl @@ -36,10 +36,25 @@ # SUCH DAMAGE. # # $My2pg: my2pg.pl,v 1.28 2001/12/06 19:32:20 fonin Exp $ -# $Id: my2pg.pl,v 1.12 2004/04/19 23:11:49 momjian Exp $ +# $Id: my2pg.pl,v 1.13 2004/04/19 23:18:12 momjian Exp $ + +# Custom patch +# Revision 1.9 2002/08/22 00:01:39 tgl +# Add a bunch of pseudo-types to replace the behavior formerly associated +# with OPAQUE, as per recent pghackers discussion. I still want to do some +# more work on the 'cstring' pseudo-type, but I'm going to commit the bulk +# of the changes now before the tree starts shifting under me ... # # $Log: my2pg.pl,v $ +# Revision 1.13 2004/04/19 23:18:12 momjian +# Update to my2pg version 1.28, add docs, update URL for newest version. +# +# Create diff of custom changes Tom made to the utility for CREATE +# FUNCTION. +# +# This will make moving this utility out of CVS easier. +# # Revision 1.12 2004/04/19 23:11:49 momjian # Update to my2pg 1.28, from: # @@ -337,11 +352,11 @@ int2* $typename"."_in (char *str) { print LIBTYPES "\n * Types for table ".uc($table_name); print LIBTYPES "\n */\n"; - $types.="\nCREATE FUNCTION $typename"."_in (opaque) + $types.="\nCREATE FUNCTION $typename"."_in (cstring) RETURNS $typename AS '$libtypename' LANGUAGE 'c' - WITH (ISCACHABLE);\n"; + WITH (ISSTRICT, ISCACHABLE);\n"; # creating output function my $func_out=" @@ -391,11 +406,11 @@ bool $typename"."_ge(int2* a, int2* b) { return (*a>=*b); }\n"; - $types.="\nCREATE FUNCTION $typename"."_out (opaque) - RETURNS opaque + $types.="\nCREATE FUNCTION $typename"."_out ($typename) + RETURNS cstring AS '$libtypename' LANGUAGE 'c' - WITH (ISCACHABLE);\n"; + WITH (ISSTRICT, ISCACHABLE);\n"; $types.="\nCREATE TYPE $typename ( internallength = 2, @@ -537,7 +552,7 @@ $typesize* $typename"."_in (char *str) { print LIBTYPES "\n * Types for table ".uc($table_name); print LIBTYPES "\n */\n"; - $types.="\nCREATE FUNCTION $typename"."_in (opaque) + $types.="\nCREATE FUNCTION $typename"."_in (cstring) RETURNS $typename AS '$libtypename' LANGUAGE 'c';\n"; @@ -589,8 +604,8 @@ $typesize find_in_set($typesize *a, $typesize *b) { \n"; - $types.="\nCREATE FUNCTION $typename"."_out (opaque) - RETURNS opaque + $types.="\nCREATE FUNCTION $typename"."_out ($typename) + RETURNS cstring AS '$libtypename' LANGUAGE 'c';\n"; @@ -762,7 +777,7 @@ close(LIBTYPES); open(MAKE,">Makefile"); print MAKE "# -# My2Pg \$Revision: 1.12 $ \translated dump +# My2Pg \$Revision: 1.13 $ \translated dump # Makefile #