X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FDBI%2FPostgreSQL.pm;h=28017a6b958308493d6efacc3f3bc8a45570df72;hb=db195df8af1efc7fb983ec6041fcb064dada7124;hp=68df21a8212259ee266e165f2132cbfebd26f8ab;hpb=f27f9229eaf8c5ce637bea1f99eb8f9bdb42799c;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm b/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm index 68df21a..28017a6 100644 --- a/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/DBI/PostgreSQL.pm @@ -20,8 +20,8 @@ use DBI; use Data::Dumper; use SQL::Translator::Schema::Constants; -use vars qw[ $DEBUG $VERSION @EXPORT_OK ]; -$VERSION = '1.59'; +our ( $DEBUG, @EXPORT_OK ); +our $VERSION = '1.59'; $DEBUG = 0 unless defined $DEBUG; my $actions = {c => 'cascade', @@ -50,10 +50,6 @@ sub parse { my $index_select = $dbh->prepare( "SELECT oid, c.relname, i.indkey, i.indnatts, i.indisunique, - ARRAY(SELECT a.attname - FROM pg_attribute a - WHERE a.attrelid=i.indrelid AND a.attnum = ANY(i.indkey) - ) AS attname, i.indisprimary, pg_get_indexdef(oid) AS create_string FROM pg_class c,pg_index i WHERE c.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname='public') AND c.relkind='i' @@ -149,13 +145,16 @@ ORDER BY 1; next if ($$indexhash{'indkey'} eq '' or !defined($$indexhash{'indkey'}) ); + my @columns = map $column_names[$_ - 1], split /\s+/, $$indexhash{'indkey'}; + my $type; if ($$indexhash{'indisprimary'}) { $type = UNIQUE; #PRIMARY_KEY; #tell sqlt that this is the primary key: - my $col_name=$column_names[($$indexhash{'indkey'} - 1)]; - $table->get_field($col_name)->{is_primary_key}=1; + for my $column (@columns) { + $table->get_field($column)->{is_primary_key}=1; + } } elsif ($$indexhash{'indisunique'}) { $type = UNIQUE; @@ -164,9 +163,6 @@ ORDER BY 1; } - my @column_ids = split /\s+/, $$indexhash{'indkey'}; - my @columns = split /\s+/, $$indexhash{'attname'}; - $table->add_index( name => $$indexhash{'relname'}, type => $type,