Subject: | PostgreSQL producer wrongly translates floating point types |
The PostgreSQL producer translates types 'real' or 'float' to 'numeric' although the former is the preferred Postgres type for 32-bit floats and the latter is standard SQL. The 'float' conversion also has the problem that the 'size' value is interpreted differently for 'float' and 'numeric' (binary vs. decimal digits).
The attached patch makes the following changes:
- Don't translate 'real' and 'float' data types
- Convert MySQL's 'double' to PostgreSQL's 'double precision'
- Support size values for 'float'
Reference: http://www.postgresql.org/docs/9.3/static/datatype-numeric.html
Subject: | pg_numeric_types.patch |
diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm
index 7fd7159..44b2cf7 100644
--- a/lib/SQL/Translator/Producer/PostgreSQL.pm
+++ b/lib/SQL/Translator/Producer/PostgreSQL.pm
@@ -43,9 +43,8 @@ BEGIN {
# MySQL types
#
bigint => 'bigint',
- double => 'numeric',
+ double => 'double precision',
decimal => 'numeric',
- float => 'numeric',
int => 'integer',
mediumint => 'integer',
smallint => 'smallint',
@@ -86,11 +85,9 @@ BEGIN {
varchar => 'character varying',
datetime => 'timestamp',
text => 'text',
- real => 'numeric',
comment => 'text',
bit => 'bit',
tinyint => 'smallint',
- float => 'numeric',
);
$max_id_length = 62;
@@ -733,7 +730,7 @@ sub convert_datatype
my $type_with_size = join('|',
'bit', 'varbit', 'character', 'bit varying', 'character varying',
- 'time', 'timestamp', 'interval', 'numeric'
+ 'time', 'timestamp', 'interval', 'numeric', 'float'
);
if ( $data_type !~ /$type_with_size/ ) {