Search code examples
sqldatatypestdengine

About TDengine supported data type


Please explain the difference between the character data type varchar and nchar in TDengine. For the storage of character data, the case provided by TDengine is compared with the traditional mysql database. Nchar is more used as the character format type instead of varchar, are there more details about the data type selection?


Solution

  • From my understanding, in mysql char/nchar is used to represent fixed length characters, while varchar/varnchar to represent variable length characters:

    https://dev.mysql.com/doc/refman/8.0/en/char.html

    For char/nchar types usually a length is specified. For example NCHAR type in TDengine is fixed to 4 bytes. If we create the column entry with type NCHAR(4), "abc" is stored as 4 bytes and trailing spaces will be used to pad the original string. However, if "abc" is stored as varchar the length will be 3. Since NCHAR is fixed length so it would be faster when operating data, but may cause additional storage overhead IMO.