string – PostgreSQL:文本和varchar之间的差异(字符变化)

前端之家收集整理的这篇文章主要介绍了string – PostgreSQL:文本和varchar之间的差异(字符变化)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
文本数据类型和字符变化(varchar)数据类型之间有什么区别?

根据the documentation

If character varying is used without length specifier,the type accepts strings of any size. The latter is a Postgresql extension.

In addition,Postgresql provides the text type,which stores strings of any length. Although the type text is not in the sql standard,several other sql database management systems have it as well.

那么有什么区别?

没有区别,在引擎盖下它是所有varlena( variable length array)。

检查这篇文章从Depesz:http://www.depesz.com/index.php/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/

几个亮点:

To sum it all up:

  • char(n) – takes too much space when dealing with values shorter than n,and can lead to subtle errors because of adding trailing
    spaces,plus it is problematic to change the limit
  • varchar(n) – it’s problematic to change the limit in live environment
  • varchar – just like text
  • text – for me a winner – over (n) data types because it lacks their problems,and over varchar – because it has distinct name

本文做了详细的测试,以显示插入和选择的性能为所有4种数据类型是类似的。它还需要详细了解在需要时限制长度的替代方法。基于函数的约束或域提供了长度约束的即时增加的优点,并且在减少字符串长度约束是罕见的基础上,depesz得出结论,其中之一通常是长度限制的最佳选择。

猜你在找的Postgre SQL相关文章