I have a table with jsonb field in table.
CREATE TABLE data.items
(
id serial NOT NULL,
datab jsonb
)
How to get size of this field in a query like this:
select id, size(datab) from data.items
I have a table with jsonb field in table.
CREATE TABLE data.items
(
id serial NOT NULL,
datab jsonb
)
How to get size of this field in a query like this:
select id, size(datab) from data.items
For the number of bytes used to store:
select id, pg_column_size(datab) from data.items;
For the number of elements on the jsonb object:
select id, jsonb_array_length(datab) from data.items;
pg_column_size
returns "Number of bytes used to store a particular value (possibly compressed)" for the curious postgresql.org/docs/12/functions-admin.html –
Keyser If the column uses EXTENDED storage (TOAST compression), you should use octet_length(datab::text)
instead of pg_column_size
octet_length
is uncompressed size, which seems more useful to me. –
Sprinkle To count the json string size:
select length(jsonb_field::text) from test;
© 2022 - 2025 — McMap. All rights reserved.
pg_column_size()
orpg_size_bytes()
postgresql.org/docs/current/static/… – Essentialism