Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 861 Bytes

determine-types-of-jsonb-records.md

File metadata and controls

30 lines (22 loc) · 861 Bytes

Determine Types Of JSONB Records

You can stick several different things into a JSONB postgres column.

Possible types are object, array, string, number, boolean, and null.

If you are trying to audit what is in them, you might reach for:

> select pg_typeof(my_jsonb_column) from my_table;

That is just gonna spit out jsonb over and over, like, I already know that.

What you really want to know is, is the top-level thing an object, an array, or maybe just a string or number. There are specific JSON processing functions for this, json_typeof and jsonb_typeof which you can call like so:

> select jsonb_typeof(my_jsonb_column) from my_table;
 jsonb_typeof
--------------
 object
 array
 ...

source