小编Veg*_*kke的帖子

Postgres中json字段的大小在压缩之前或之后有限制吗?

json 字段的大小限制为 1GB(来源:此 StackOverflow 答案):

json与数据类型相同text,但具有 JSON 验证。数据text类型的最大大小为 1GB。

我进行了一些实验,将json不同大小的数据插入到 Postgres 的表中。这里的行pg_sizeof似乎表明 Postgres 对 json 数据进行了压缩。

我的实验:

create table json_size (n integer, j json);
Run Code Online (Sandbox Code Playgroud)

值为n1、10、100、1000、10 000、100 000、1 000 000。

with q as (select generate_series(1, n)::bigint as x)               
insert into json_size (n, j)
select 1, coalesce(json_agg(to_json(q.*)), '[]'::json) from q;
Run Code Online (Sandbox Code Playgroud)
select n, pg_column_size(j) as size from json_size;
Run Code Online (Sandbox Code Playgroud)

结果

n       size
1       10
10      92
100     996
1000    3224
10000 …
Run Code Online (Sandbox Code Playgroud)

postgresql json

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

json ×1

postgresql ×1