'decode error when selecting from single table but not when selecting from joined table in python using pymssql
I get a unicode decode error when I'm selecting from table b, but not when I'm selecting (the same columns) from table a left join table b. If there is a decoding error why won't I get the error message in the second case, and how do i fix the problem? (if i change the encoding to utf8, I don't get the error but one of my columns becomes weird characters
con = pymssql.connect(host=host,
user=user_id,
password=password,
database=db,
charset='big5')
sql_query = '''
SELECT [col1]
,[col2]
,[col3]
FROM b
'''
data = pd.read_sql_query(sql_query, con)
error message:
UnicodeDecodeError: 'big5' codec can't decode byte 0x9d in position 4: illegal multibyte sequence
But this doesn't
con = pymssql.connect(host=host,
user=user_id,
password=password,
database=db,
charset='big5')
sql_query = '''
SELECT a.[col1]
,a.[col2]
,a.[col3]
,b.[col1]
,b.[col2]
,b.[col3]
FROM table_a a
LEFT JOIN table_b b
ON a.[col1] = b.[col1]
WHERE i.[DELETE_MARK] = 0 AND i.[TOTAL_UNIT] > 0
'''
data = pd.read_sql_query(sql_query, con)
udpate: Apparently, col2 has one data that isn't in big5, that is why I got the error when I select from b. But that still doesn't explain why I don't get this error when I selected from a left join b
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
