DECIMAL accepts precision and scale

Issue #2618 resolved
Mike Bayer repo owner created an issue

backport to 0.7 also

Comments (5)

  1. Former user Account Deleted

    (original author: diana) Is this all that needs changing (aside from backport to 0.7)?

    diff -r 65dd01233f757e70aa9c7a8b5f92386ac066a46c lib/sqlalchemy/sql/compiler.py
    --- a/lib/sqlalchemy/sql/compiler.py    Thu Nov 29 17:28:56 2012 -0500
    +++ b/lib/sqlalchemy/sql/compiler.py    Fri Nov 30 23:15:18 2012 -0500
    @@ -2084,7 +2084,15 @@
                             '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 -r 65dd01233f757e70aa9c7a8b5f92386ac066a46c test/sql/test_types.py
    --- a/test/sql/test_types.py    Thu Nov 29 17:28:56 2012 -0500
    +++ b/test/sql/test_types.py    Fri Nov 30 23:15:18 2012 -0500
    @@ -1306,6 +1306,23 @@
                     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)')
    
  2. Log in to comment