diff --git a/README.md b/README.md index 6289804..2e04a35 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_932 TILs and counting..._ +_933 TILs and counting..._ --- @@ -457,6 +457,7 @@ _932 TILs and counting..._ - [Day Of Week For A Date](postgres/day-of-week-for-a-date.md) - [Default Schema](postgres/default-schema.md) - [Defining Arrays](postgres/defining-arrays.md) +- [Determine Types Of JSONB Records](postgres/determine-types-of-jsonb-records.md) - [Determining The Age Of Things](postgres/determining-the-age-of-things.md) - [Difference Between Explain And Explain Analyze](postgres/difference-between-explain-and-explain-analyze.md) - [Dump And Restore A Database](postgres/dump-and-restore-a-database.md) diff --git a/postgres/determine-types-of-jsonb-records.md b/postgres/determine-types-of-jsonb-records.md new file mode 100644 index 0000000..e87e6bc --- /dev/null +++ b/postgres/determine-types-of-jsonb-records.md @@ -0,0 +1,30 @@ +# Determine Types Of JSONB Records + +You can stick several different things into a [JSONB postgres +column](https://www.postgresql.org/docs/9.4/datatype-json.html). + +> Possible types are object, array, string, number, boolean, and null. + +If you are trying to audit what is in them, you might reach for: + +```sql +> 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: + +```sql +> select jsonb_typeof(my_jsonb_column) from my_table; + jsonb_typeof +-------------- + object + array + ... +``` + +[source](https://www.postgresql.org/docs/9.5/functions-json.html)