Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size limit of JSON data type in PostgreSQL

Does anyone know what is the limit on the size of JSON data type in PostgreSQL 9.2?

like image 210
ankurvsoni Avatar asked Sep 28 '12 02:09

ankurvsoni


People also ask

What is the size of JSON in PostgreSQL?

The size limit of a json field is 1GB (source: this StackOverflow answer): json is the same as a text datatype but with JSON validation. The text datatype's maximum size is 1GB.

Is there a limit to JSON size?

How large can JSON Documents be? One of the more frequently asked questions about the native JSON data type, is what size can a JSON document be. The short answer is that the maximum size is 1GB. However, JSON often changes how data modeling is done, and deserves a slightly longer response.

Does Postgres support JSON data type?

PostgreSQL offers two types for storing JSON data: json and jsonb . To implement efficient query mechanisms for these data types, PostgreSQL also provides the jsonpath data type described in Section 8.14. 7. The json and jsonb data types accept almost identical sets of values as input.


1 Answers

Looking at the source for PostgreSQL 9.2.1:

Source: postgresql-9.2.1\src\backend\utils\adt\json.c: /*  * Input.  */ Datum json_in(PG_FUNCTION_ARGS) {     char       *text = PG_GETARG_CSTRING(0);      json_validate_cstring(text);      /* Internal representation is the same as text, for now */     PG_RETURN_TEXT_P(cstring_to_text(text)); } 

Update for PostgreSQL 9.3.5:

The code has changed in the json_in function, but the json internal representation is still text:

Source: postgresql-9.3.5\src\backend\utils\adt\json.c: /*  * Input.  */ Datum json_in(PG_FUNCTION_ARGS) {     char       *json = PG_GETARG_CSTRING(0);     text       *result = cstring_to_text(json);     JsonLexContext *lex;      /* validate it */     lex = makeJsonLexContext(result, false);     pg_parse_json(lex, &nullSemAction);      /* Internal representation is the same as text, for now */     PG_RETURN_TEXT_P(result); } 

So it appears that, for now at least, json is the same as a text datatype but with JSON validation. The text datatype's maximum size is 1GB.

like image 148
j.w.r Avatar answered Oct 14 '22 13:10

j.w.r