加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 16:58:03 所属栏目:百科 来源:网络整理
导读:文本数据类型和字符变化(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 provi
文本数据类型和字符变化(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得出结论,其中之一通常是长度限制的最佳选择。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读