0

I am trying to insert a text column of into a Redshift DB.

I get an error

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

Given below is the code I tried. The description column has text and the length goes upto 2000 characters.

Could anyone assist on how I could have this column inserted into the table.

 DF['description'] = DF['description'].str[:200].astype(str)

Could anyone assist, thanks.

dark horse
  • 3,211
  • 8
  • 19
  • 35
  • probably extended character set, try increasing it to 400 and see if that works – Jon Scott Jul 04 '18 at 18:57
  • @JonScott, it throws an error when I try with 200 characters itself. – dark horse Jul 11 '18 at 10:41
  • did you try what i suggested? increase the TARGET to 400 (or maybe more) but leave the source the same (ie 200) – Jon Scott Jul 11 '18 at 14:05
  • @JonScott, the below worked for me. DF['description'] = DF['description'].str.slice(0,250). Tried increasing the column length to be 300 but it threw the same error.. – dark horse Jul 12 '18 at 14:14

1 Answers1

0

You should be using str.slice.

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

Please note that this function works only in case of Strings or you may have to typecast.

Hope it helps.

Red Boy
  • 5,429
  • 3
  • 28
  • 41
  • `df['description'] = df['description'].str.slice(0,254)` if it doesn't work, I have read it in some other question that size was 2 but `Redshift` was expecting one additional character length, though I don't believe should be the case. – Red Boy Jul 05 '18 at 13:16
  • sorry for the late reply. Tried the above suggestion but it threw the same error even when I tried str.slice(0,250). – dark horse Jul 11 '18 at 10:41