Archiv verlassen und diese Seite im Standarddesign anzeigen : mysql -> postgresql
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...
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
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
naja, nun ist's zu spät...
Powered by vBulletin® Version 4.2.5 Copyright ©2024 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.