diff options
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 10 | ||||
-rw-r--r-- | test/sql/test_types.py | 17 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 102b44a7e..215ecf7bd 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2084,7 +2084,15 @@ class GenericTypeCompiler(engine.TypeCompiler): 'scale': type_.scale} def visit_DECIMAL(self, type_): - return "DECIMAL" + if type_.precision is None: + return "DECIMAL" + elif type_.scale is None: + return "DECIMAL(%(precision)s)" % \ + {'precision': type_.precision} + else: + return "DECIMAL(%(precision)s, %(scale)s)" % \ + {'precision': type_.precision, + 'scale': type_.scale} def visit_INTEGER(self, type_): return "INTEGER" diff --git a/test/sql/test_types.py b/test/sql/test_types.py index f9ab785ed..8987743d4 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -1306,6 +1306,23 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): dialects.mysql.INTEGER(display_width=5), "INTEGER(5)", allow_dialect_select=True) + def test_numeric_plain(self): + self.assert_compile(types.NUMERIC(), 'NUMERIC') + + def test_numeric_precision(self): + self.assert_compile(types.NUMERIC(2), 'NUMERIC(2)') + + def test_numeric_scale(self): + self.assert_compile(types.NUMERIC(2, 4), 'NUMERIC(2, 4)') + + def test_decimal_plain(self): + self.assert_compile(types.DECIMAL(), 'DECIMAL') + + def test_decimal_precision(self): + self.assert_compile(types.DECIMAL(2), 'DECIMAL(2)') + + def test_decimal_scale(self): + self.assert_compile(types.DECIMAL(2, 4), 'DECIMAL(2, 4)') |