PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : mysql -> postgresql



elrond
22-09-2004, 08:02
hallo allerseits,

kennt ihr ein tool, das ein mittels mysqldump erzeugtes file für postgresql nutzbar macht?

im mysqldump ist zB. int(11) im weg...

Jasper
22-09-2004, 09:28
kennt ihr ein tool, das ein mittels mysqldump erzeugtes file für postgresql nutzbar macht?

im mysqldump ist zB. int(11) im weg...

z.b. sed, mit search-and-replace sollte das problem zu lösen sein.


-j

elrond
22-09-2004, 09:53
die sache ist etwas komplexer...

ich habe ein stück perl dazu geschrieben. ist sicherlich nicht schön, tut aber genau was ich brauche...



#!/usr/bin/perl -w

@inline=<stdin>;

my $tbl=0;
my $cr="";
my $tabname;
my @fields;
my @tabkeys;
my $idxcnt=0;
foreach $_ (@inline) {
$ln=$_;
chomp($ln);
if($ln=~ /CREATE/) {
$tbl=1;
@elm=split(" ",$ln);
$tabname=$elm[2];
}
if($ln=~ /^\)/) {
$tbl=0;
print "\n-- Tabelle ".$tabname."\n\n";
print $cr."\n",join(",\n",@fields)."\n);\n\n";
print join("\n",@tabkeys)."\n\n\n";
$cr="";
undef @fields;
undef @tabkeys;
$idxcnt=0;
}
if($tbl==1 ) {
if ($ln=~ /CREATE/) { $cr=$ln;}
else {
$ln=~ s/int\(\d+\)/int/;
$ln=~ s/\,$//g;
if($ln=~ /KEY/) {
if($ln=~ /PRIMARY/) {
my $keystr=" alter table ".$tabname." add constraint pk_".$tabname." ";
$tabkeys[(@tabkeys)]=$keystr.$ln.";";
}
else {
@elm=split(" ",$ln);
$idxcnt++;
my $keystr=" create index idx_".$tabname."_".sprintf("%02d",$idxcnt)." on ".$tabname." using btree ".$elm[2].";";
$tabkeys[(@tabkeys)]=$keystr;
}
}
else {
@elm=split(" ",$ln);
if($ln=~ /datetime/ ) {
$ln=" ".$elm[0]." TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL";
}
if($ln=~ /tinyint/ ) {
$ln=~ s/tinyint/int/;
}
if($ln=~ /tinytext/ ) {
$ln=~ s/tinytext/text/;
}
$ln=~ s/$elm[0]/\"$elm[0]\"/;
$fields[(@fields)]= $ln;
}
}
}

if($ln=~ /^INSERT/) {
print $ln."\n";
}
}

Christoph
22-09-2004, 11:30
Wie eine Google-SUche nach "mysql postgresql mysqldump" zeigt, musst Du das Rad nicht neu erfinden. Schau z.B. mal hier: http://www.rot13.org/~dpavlin/sql.html

elrond
22-09-2004, 11:38
naja, nun ist's zu spät...