Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that numeric precision is included only if not None #796

Merged
merged 3 commits into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dbt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<Column {} ({})>".format(self.name, self.data_type)
Expand Down
4 changes: 4 additions & 0 deletions test/integration/008_schema_tests_test/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
23 changes: 23 additions & 0 deletions test/unit/test_schema.py
Original file line number Diff line number Diff line change
@@ -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')