Permalink
Browse files

Simple change to make Postgres simple array types produce correctly

  • Loading branch information...
1 parent 3f5ee66 commit aacb31871ec4c0eaf0c4c89287c4ac395063625f @colinnewell colinnewell committed with ribasushi Apr 18, 2011
Showing with 23 additions and 1 deletion.
  1. +1 −0 AUTHORS
  2. +2 −0 Changes
  3. +5 −0 lib/SQL/Translator/Producer/PostgreSQL.pm
  4. +15 −1 t/47postgres-producer.t
View
1 AUTHORS
@@ -9,6 +9,7 @@ The following people have contributed to the SQLFairy project:
- Chris Hilton <chilton@alterpoint.com>
- Chris Mungall <cjm@fruitfly.org>
- Chris To <christot@users.sourceforge.net>
+- Colin Newell <colin.newell@gmail.com>
- Daniel Ruoso <daniel@ruoso.com>
- Darren Chamberlain <dlc@users.sourceforge.net>
- Dave Cash <dave@gnofn.org>
View
2 Changes
@@ -8,6 +8,8 @@
* Quote everything in SQL Server
* Turn off constraints before dropping tables in SQL Server
* Make true unique constraints if needed in SQL Server
+* Fixed Producer::PostgresSQL to output array type after type size,
+ i.e. varchar(64)[] rather than varchar[](64)
# ----------------------------------------------------------
# 0.11007 2010-11-30
View
5 lib/SQL/Translator/Producer/PostgreSQL.pm
@@ -674,6 +674,7 @@ sub convert_datatype
my @size = $field->size;
my $data_type = lc $field->data_type;
+ my $array = $data_type =~ s/\[\]$//;
if ( $data_type eq 'enum' ) {
# my $len = 0;
@@ -740,6 +741,10 @@ sub convert_datatype
} elsif ( defined $size[0] && $size[0] > 0 ) {
$data_type .= '(' . join( ',', @size ) . ')';
}
+ if($array)
+ {
+ $data_type .= '[]';
+ }
#
# Geography
View
16 t/47postgres-producer.t
@@ -14,7 +14,7 @@ use FindBin qw/$Bin/;
#=============================================================================
BEGIN {
- maybe_plan(38,
+ maybe_plan(39,
'SQL::Translator::Producer::PostgreSQL',
'Test::Differences',
)
@@ -40,6 +40,20 @@ my $field1_sql = SQL::Translator::Producer::PostgreSQL::create_field($field1);
is($field1_sql, 'myfield character varying(10)', 'Create field works');
+my $field_array = SQL::Translator::Schema::Field->new( name => 'myfield',
+ table => $table,
+ data_type => 'character varying[]',
+ size => 10,
+ default_value => undef,
+ is_auto_increment => 0,
+ is_nullable => 1,
+ is_foreign_key => 0,
+ is_unique => 0 );
+
+my $field_array_sql = SQL::Translator::Producer::PostgreSQL::create_field($field_array);
+
+is($field_array_sql, 'myfield character varying(10)[]', 'Create field works');
+
my $field2 = SQL::Translator::Schema::Field->new( name => 'myfield',
table => $table,
data_type => 'VARCHAR',

0 comments on commit aacb318

Please sign in to comment.