database PostgreSQL 中的 CHARACTER VARYING 和 VARCHAR 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1199468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between CHARACTER VARYING and VARCHAR in PostgreSQL?
提问by Léo Léopold Hertz ??
Johnuses 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.
约翰用CHARACTER VARYING
在我使用的地方VARCHAR
。我是初学者,而他是专家。这表明我有一些我不知道的事情。
What is the difference between CHARACTER VARYING and VARCHAR in PostgreSQL?
PostgreSQL 中的 CHARACTER VARYING 和 VARCHAR 有什么区别?
回答by Charles Ma
Varying is an alias for varchar, so no difference, see documentation:)
Varying 是 varchar 的别名,所以没有区别,请参阅文档:)
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.
符号 varchar(n) 和 char(n) 分别是字符变化 (n) 和字符 (n) 的别名。没有长度说明符的字符等价于 character(1)。如果在没有长度说明符的情况下使用字符变化,则该类型接受任何大小的字符串。后者是 PostgreSQL 扩展。
回答by Greg Hewgill
The PostgreSQL documentation on Character Typesis a good reference for this. They are two different names for the same type.
关于字符类型的PostgreSQL 文档是一个很好的参考。它们是同一类型的两个不同名称。
回答by inor
The only difference is that CHARACTER VARYING is more human friendly than VARCHAR
唯一的区别是 CHARACTER VARYING 比 VARCHAR 更人性化
回答by Daya Shanker
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
两者都是一样的,但许多数据库没有提供主要是 postgreSQL 提供的不同字符。所以对于像 Oracle Postgre 和 DB2 这样的多数据库,最好使用 Varchar
回答by Gordon Hopper
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. 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
.
长答案:CHARACTER VARYING
是来自 ANSI SQL 标准的官方类型名称,所有兼容的数据库都需要支持。VARCHAR
是一个较短的别名,所有现代数据库也支持。我更喜欢,VARCHAR
因为它更短,因为更长的名字让人感觉迂腐。但是,postgres 工具喜欢pg_dump
并且\d
会输出character varying
.