diff --git a/dbt/schema.py b/dbt/schema.py index b66cf95a821..944ede0e0fc 100644 --- a/dbt/schema.py +++ b/dbt/schema.py @@ -57,7 +57,10 @@ def string_type(cls, size): def numeric_type(cls, dtype, size): # This could be decimal(...), numeric(...), number(...) # Just use whatever was fed in here -- don't try to get too clever - return "{}({})".format(dtype, size) + if size is None: + return dtype + else: + return "{}({})".format(dtype, size) def __repr__(self): return "".format(self.name, self.data_type) diff --git a/test/integration/008_schema_tests_test/seed.sql b/test/integration/008_schema_tests_test/seed.sql index 3de2d1a234b..8f1801504ca 100644 --- a/test/integration/008_schema_tests_test/seed.sql +++ b/test/integration/008_schema_tests_test/seed.sql @@ -3,6 +3,10 @@ create table {schema}.seed ( id INTEGER, first_name VARCHAR(11), email VARCHAR(31), + + net_worth NUMERIC(12, 2) DEFAULT '100.00', + fav_number NUMERIC DEFAULT '3.14159265', + ip_address VARCHAR(15), updated_at TIMESTAMP WITHOUT TIME ZONE ); diff --git a/test/unit/test_schema.py b/test/unit/test_schema.py new file mode 100644 index 00000000000..a7c3d94fff0 --- /dev/null +++ b/test/unit/test_schema.py @@ -0,0 +1,23 @@ +import unittest + +import dbt.schema + + +class TestNumericType(unittest.TestCase): + + def test__numeric_type(self): + col = dbt.schema.Column( + 'fieldname', + 'numeric', + numeric_size='12,2') + + self.assertEqual(col.data_type, 'numeric(12,2)') + + def test__numeric_type_with_no_precision(self): + # PostgreSQL, at least, will allow empty numeric precision + col = dbt.schema.Column( + 'fieldname', + 'numeric', + numeric_size=None) + + self.assertEqual(col.data_type, 'numeric')