Sipmlify Pg enum value fetching
Dagfinn Ilmari Mannsåker [Sun, 13 Sep 2015 16:39:34 +0000 (17:39 +0100)]
lib/DBIx/Class/Schema/Loader/DBI/Pg.pm

index 131fbd3..1e751e2 100644 (file)
@@ -289,11 +289,10 @@ FROM pg_catalog.pg_type
 WHERE typname = ?
 EOF
             if ($typetype && $typetype eq 'e') {
-                # The following will extract a list of allowed values for the
-                # enum.
+                # The following will extract a list of allowed values for the enum.
                 my $order_column = $self->dbh->{pg_server_version} >= 90100 ? 'enumsortorder' : 'oid';
-                my $typevalues = $self->dbh
-                    ->selectall_arrayref(<<EOF, {}, $info->{data_type});
+                $info->{extra}{list} = $self->dbh
+                    ->selectcol_arrayref(<<EOF, {}, $info->{data_type});
 SELECT e.enumlabel
 FROM pg_catalog.pg_enum e
 JOIN pg_catalog.pg_type t ON t.oid = e.enumtypid
@@ -301,8 +300,6 @@ WHERE t.typname = ?
 ORDER BY e.$order_column
 EOF
 
-                $info->{extra}{list} = [ map { $_->[0] } @$typevalues ];
-
                 # Store its original name in extra for SQLT to pick up.
                 $info->{extra}{custom_type_name} = $info->{data_type};