PostgreSQL 中的 CHARACTER VARYING 和 VARCHAR 有什么区别?
John 使用 CHARACTER VARYING
在我使用 VARCHAR
的地方。 我是初学者,而他是专家。 这表明我有一些我不知道的事情。
PostgreSQL 中的 CHARACTER VARYING 和 VARCHAR 有什么区别?
John uses CHARACTER VARYING
in the places where I use VARCHAR
.
I am a beginner, while he is an expert.
This suggests me that there is something which I do not know.
What is the difference between CHARACTER VARYING and VARCHAR in PostgreSQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
VARCHAR
是CHARACTER VARYING
的别名,因此没有区别,请参阅 文档 :)关于大小写的注意事项:PostgreSQL 文档使用全小写的样式:
character Varying
。 相比之下,官方 SQL 标准在其 1000 页中使用全部大写的样式:CHARACTER VARYING
。VARCHAR
is an alias forCHARACTER VARYING
, so no difference, see documentation :)Note on capitalization: The PostgreSQL documentation uses the all lower case stylization:
character varying
. In contrast the official SQL standard uses the stylization with all caps throughout its 1000 pages:CHARACTER VARYING
.有关字符类型的 PostgreSQL 文档 是一个很好的参考。 它们是同一类型的两个不同名称。
The PostgreSQL documentation on Character Types is a good reference for this. They are two different names for the same type.
简短回答:没有区别。
长答案:
CHARACTER VARYING
是 ANSI SQL 标准的正式类型名称,所有兼容的数据库都需要支持。 (SQL 合规性功能 ID E021-02。)VARCHAR
是所有现代数据库都支持的较短别名。 我更喜欢VARCHAR
,因为它更短,而且较长的名称让人感觉迂腐。 但是,像pg_dump
和\d
这样的 postgres 工具将输出字符变化
。The short answer: there is no difference.
The long answer:
CHARACTER VARYING
is the official type name from the ANSI SQL standard, which all compliant databases are required to support. (SQL compliance Feature ID E021-02.)VARCHAR
is a shorter alias which all modern databases also support. I preferVARCHAR
because it's shorter and because the longer name feels pedantic. However, postgres tools likepg_dump
and\d
will outputcharacter varying
.唯一的区别是
CHARACTER VARYING
比VARCHAR
更人性化The only difference is that
CHARACTER VARYING
is more human friendly thanVARCHAR
两者是相同的东西,但许多数据库不提供主要是 postgreSQL 提供的不同字符。 因此,对于像 Oracle Postgre 和 DB2 这样的多数据库,最好使用 Varchar
Both are the same thing but many of the databases are not providing the varying char mainly postgreSQL is providing. So for the multi database like Oracle Postgre and DB2 it is good to use the Varchar