0

I am trying to update data from JIRA to Redshift DB using python. I am having issues updating value from 'description' column. The target column in DB is of type varchar.

Given below is how I modify the 'description' column before inserting it into Redshift DB.

df['description'] = df['description'].astype(str)

And it throws the below error:

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

Is there anything wrong that I am doing to have this field inserted. Length of values in the description column go upto 6000 characters.

Any help on this, would be appreciated..

Kevin Nash
  • 1,511
  • 3
  • 18
  • 37

1 Answers1

0

Probably duplicate of this.

df['description'] = df['description'].str.slice(0,255)

EDIT AFTER COMMENT Here is my fully working example.

import pandas as pd

d = {'name' : pd.Series(['FFFFF', 'FFFFF', 'FFFFFGGGGg'], index=['a', 'b', 'c']),
     'description' : pd.Series(['FFFFF', 'FFFFF', 'FFFFFGGGGg','4666666666'], index=['a', 'b', 'c', 'd']),
     'place' : pd.Series(['166666660', '26666666660', '3666666660'], index=['a', 'b', 'c'])}

df = pd.DataFrame(d)
print ("Our dataframe is:")
print (df)

print ("Modifying column description:")

df['description'] = df['description'].str.slice(0,4)
print(df)
Red Boy
  • 5,429
  • 3
  • 28
  • 41
  • 1
    thanks for the reply. Tried using your suggestion "df['description'].str.slice(0,255)". It throws an error "ProgrammingError: can't adapt type 'dict'". – Kevin Nash Jul 06 '18 at 13:06
  • Not sure why you are getting an exception, I have just added my full working example, which one of line I shared earlier. Hope it helps. – Red Boy Jul 06 '18 at 13:56
  • I think, can't adapt might be because of datatype mismatch, though not sure. – Red Boy Jul 06 '18 at 14:00
  • Wondering how to address this since my source column length is more than 256 characters but the target column type is varchar. Believe this is causing an issue.. – Kevin Nash Jul 06 '18 at 14:13
  • `str.slice(0,4)` is converting orignal length to 4 characters, similarly (0,255) will truncate from any length to 255 character. – Red Boy Jul 06 '18 at 15:22