24

What's the best data type to use for a column in a redshift table that will hold a very long string (can be up to 50KB)?

TEXT is replaced by varchar(256) by default. For now I used varchar(65535), but I'm not sure if that's the right way to do that...

Thanks

WeaselFox
  • 7,220
  • 8
  • 44
  • 75

2 Answers2

30

Text Data Type in Redshift:

For Redshift Text Data Type you can use varchar(max) or varchar(65535)

That is the maximum length of a text data type field in Redshift.

Tech Support
  • 948
  • 11
  • 9
4

VARCHAR, CHARACTER VARYING and NVARCHAR can have a length of up to 65k.

Source: http://docs.aws.amazon.com/redshift/latest/dg/r_Character_types.html

Peanut
  • 3,753
  • 3
  • 31
  • 45
  • yes, I saw these docs, see my edit. Still not sure that's the best way to store this data. – WeaselFox Jun 18 '15 at 15:20
  • I have not found any other types that can hold more data. I don't think there are any types better suited for this. Although there might be a better way (other DBMS or a filesystem?) than to store the whole text inside one column. – Peanut Jun 18 '15 at 15:24
  • this would mean I suppose that every record in the table is allocated 65k regardless of the actual length of the text.. – WeaselFox Jun 18 '15 at 15:29
  • No, it does not. Read the part about varchar in the link above: > Use a VARCHAR or CHARACTER VARYING column to store variable-length strings with a fixed limit. These strings are not padded with blanks, so a VARCHAR(120) column consists of a maximum of 120 single-byte characters, 60 two-byte characters, 40 three-byte characters, or 30 four-byte characters. – Peanut Jun 18 '15 at 15:50
  • It seems to be "4 bytes + total bytes for characters" according to http://dba.stackexchange.com/questions/99361/storage-size-for-varchar-length-in-redshift – Peanut Jun 19 '15 at 06:18
  • 3
    However, you should be cautious of having too large columns. Amazon themeselves recommend keeping it as small as possible, because when doing complex queries the data will not be compressed: http://docs.aws.amazon.com/redshift/latest/dg/c_best-practices-smallest-column-size.html – user2694306 Jul 19 '16 at 14:57