我知道在 PostgreSQL 中, VARCHAR(n)
等效于 SQL Server 的NVARCHAR(n)
,但是我如何在 PostgreSQL 中使用类似于VARCHAR(MAX)
东西,类似于 SQL Server 中的NVARCHAR(MAX)
东西?
In PostgreSQL for char(n)
and varchar(n)
it is just limited by n
argument (not sure about nature of such limitation, it seems that it is 20 Mb or 10M of 2-bytes characters or something):
postgres=# select 'a'::varchar(999999999);
ERROR: length for type varchar cannot exceed 10485760
So if you really need the equivalent for MS SQL Server nvarchar(max)
- it could be varchar(10485760)
However to use really unlimited character values there are two ways: varchar
or character varying
without argument or just text
type. Read more in thedocumentation and note about Tip provided in it:
There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.
If you want to created an "unbounded" varchar
column just use varchar
without a length restriction.
If character varying is used without length specifier, the type accepts strings of any size
So you can use:
create table foo
(
unlimited varchar
);
Another alternative is to use text
:
create table foo
(
unlimited text
);
More details about character data types are in the manual:
http://www.postgresql.org/docs/current/static/datatype-character.html
text, varchar can be used for this requirement. i used varchar
Character Types Description
character varying(n), varchar(n) --- variable-length with limit
character(n), char(n) -- fixed-length, blank padded
text, varchar -- variable unlimited length
More Details: https://www.postgresqltutorial.com/postgresql-char-varchar-text/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.