Search code examples
python-3.xpandasamazon-redshiftstring-length

How to increase default variable length in Python


Is there a way to increase default variable length in Python (I think default is 255 for string ?) ? For example in SAS there is a length statement to assign a fixed length to a certain variable. It works like- LENGTH variable-list $ number-of-bytes;

The reason I want to do that is this error:

DataError: value too long for type character varying(256)

I am trying to write a pandas data frame to redshift but its not working because of the above error. Now I have almost 400 variables/columns, most of them are string type (basically description or comments) and its not possible to check each variable to find the problem. Also a point to be noted is pandas data frame is considering those string or varchar type columns as 'object' type.

I have tried to search the issue, but not seeing much information.


Solution

  • What you're encountering is a limit set in your Redshift schema, not in python or pandas. Redshift is based on PostgreSQL, so you may find the answers here to be useful.