How to get size of PostgreSQL jsonb field?

mystdeim picture mystdeim · Nov 5, 2016 · Viewed 13.6k times · Source

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

Answer

dopeddude picture dopeddude · Sep 18, 2017

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;