PostgreSQL 中的 CHARACTER VARYING 和 VARCHAR 有什么区别?

发布于 2024-07-30 09:12:23 字数 312 浏览 15 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

回首观望 2024-08-06 09:12:23

VARCHARCHARACTER VARYING 的别名,因此没有区别,请参阅 文档 :)

符号 varchar(n)char(n)character Varying(n)character(n) 的别名),分别。 不带长度说明符的 character 相当于 character(1)。 如果在没有长度说明符的情况下使用字符变化,则该类型接受任何大小的字符串。 后者是 PostgreSQL 扩展。

关于大小写的注意事项:PostgreSQL 文档使用全小写的样式:character Varying。 相比之下,官方 SQL 标准在其 1000 页中使用全部大写的样式:CHARACTER VARYING

VARCHAR is an alias for CHARACTER VARYING, so no difference, see documentation :)

The notations varchar(n) and char(n) are aliases for character varying(n) and character(n), respectively. character without length specifier is equivalent to character(1). If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.

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.

你又不是我 2024-08-06 09:12:23

有关字符类型的 PostgreSQL 文档 是一个很好的参考。 它们是同一类型的两个不同名称。

The PostgreSQL documentation on Character Types is a good reference for this. They are two different names for the same type.

Oo萌小芽oO 2024-08-06 09:12:23

简短回答:没有区别。

长答案: 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 prefer VARCHAR because it's shorter and because the longer name feels pedantic. However, postgres tools like pg_dump and \d will output character varying.

奶茶白久 2024-08-06 09:12:23

唯一的区别是 CHARACTER VARYINGVARCHAR 更人性化

The only difference is that CHARACTER VARYING is more human friendly than VARCHAR

喜你已久 2024-08-06 09:12:23

两者是相同的东西,但许多数据库不提供主要是 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文