I am trying to read data from a MS SQL table, and one of the columns contains varchar's larger than 1024 characters. When I've read the query into a dataframe, the strings are truncated at 1023 characters. See the code below and the output. Does anyone know how I can get strings larger than 1023 chars into the dataframe ? I've been looking around, and in the DataFrame docs, but I haven't found an answer.
In the code below table test contains a column 's' where one of the rows has a string of length 1100. The column 'len_s' contains the length of the string 's' (calculated in SQL server).
import pypyodbc
from pandas import Series, DataFrame
import pandas as pd
#print("set connection string ...")
connection_string ='Driver={SQL Server Native Client 11.0};Server= ....'
#connect to SQL server
con = pypyodbc.connect(connection_string)
query="select a, s, len(s) as len_s from test"
df=pd.read_sql_query(query, con)
print(df)
print(len(df['s'][1]))
The output is:
a s len_s
0 1 01234567890 11
1 2 0123456789012345678901234567890123456789012345... 1100
1023
So in the dataframe the string is truncated... Any suggestions ?