Skip to content
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
2 changes: 2 additions & 0 deletions Orange/data/sql/backend/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def _guess_variable(self, field_name, field_metadata, inspect_table):
if type_code in CHAR_TYPES:
if inspect_table:
values = self.get_distinct_values(field_name, inspect_table)
# remove trailing spaces
values = [v.rstrip() for v in values]
Copy link
Member

@astaric astaric Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not modify the query to cast to ::text like it will be done in further selects?

Copy link
Collaborator Author

@robertcv robertcv Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_distinct_values encapsulates filed_name into quotes and the query becomes invalid. On request, I can move the encapsulation from get_distinct_values and add it outside function calls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it is ok the way it is.

if values:
return DiscreteVariable.make(field_name, values)

Expand Down
8 changes: 8 additions & 0 deletions Orange/tests/sql/test_sql_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ def test_discrete_char(self):
sql_table = SqlTable(conn, table_name, inspect_values=True)
self.assertFirstAttrIsInstance(sql_table, DiscreteVariable)

def test_discrete_bigger_char(self):
"""Test if the discrete values are the same for bigger char fields"""
table = np.array(['M', 'F', 'M', 'F', 'M', 'F']).reshape(-1, 1)
conn, table_name = self.create_sql_table(table, ['char(10)'])

sql_table = SqlTable(conn, table_name, inspect_values=True)
self.assertSequenceEqual(sql_table.domain[0].values, ['F', 'M'])

def test_meta_char(self):
table = np.array(list('ABCDEFGHIJKLMNOPQRSTUVW')).reshape(-1, 1)
conn, table_name = self.create_sql_table(table, ['char(1)'])
Expand Down