---
name: "my2pg.pl"
section: "1"
platform: "linux"
package: "postgresql-contrib"
version: "7.4.7-6sarge6"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/my2pg.pl"
---

# my2pg.pl(1)

MySQL -\> PostgreSQL dump conversion utility.

## NAME

my2pg - MySQL -\> PostgreSQL dump conversion utility.

## SYNTAX

```
        mysqldump db ⎪ ./my2pg.pl [-n] > 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:

- Type conversion.

  It tries to find proper Postgres  type for each column. Unknown types are silently pushing to output dump; ENUM and SET types implemented via user types  (C source for such types can be found in  **libtypes.c** file);

- Identifiers double-quotation.

  All column and table  names should be enclosed to double-quotes to prevent  interferension with reserved words;

- Converting

  AUTO\_INCREMENT fields to SERIAL. Actually, creating the sequence and  setting default value to nextval('seq'), well, you know :)

- Converting

  KEY(field) to CREATE INDEX i\_field on table (field);

- The same

  for UNIQUE keys;

- Indices

  are creating AFTER rows insertion (to speed up the load);

- Translates '#'

  MySQL comments to ANSI SQL '--'

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.

## SIDE EFFECTS

- creates

  file **libtypes.c** in current directory  overwriting existed file without any checks;

- the same

  for Makefile.

## BUGS

This program is still beta. Testers wanted. Known bugs are:

- Poor doublequotation.

  All identifiers such as table and column names should be enclosed in double  quotes. Program can't handle upper-case identifiers,  like DBA. Lower-case identifiers are OK.

- SET type emulation is not full. LIKE operation on

  SETs, raw integer input values should be implemented

- **Makefile** generated during output is platform-dependent and surely works only on Linux/gcc (FreeBSD/gcc probably works as well - not tested)

  - Generated **libtypes.c** contain line

  ```
          #include <postgres.h>
  ```

  This file may be located not in standard compiler  include path, you need to check it before compiling.

## AUTHORS

**(c) 2000 Maxim V. Rudensky	 (fonin@ziet.zhitomir.ua)** **(c) 2000 Valentine V. Danilchuk (valdan@ziet.zhitomir.ua)**

## CREDITS

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\>

## LICENSE

**BSD**
