# Adding jsonb columns for custom fields

**URL:** <https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418>\
**Category:** Development\
**Created:** [7월 29, 2018, 6:55오후 UTC](https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418 "2018-07-29T18:55:48Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [7월 29, 2018, 7:16오후 UTC](https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418/3 "2018-07-29T19:16:31Z")

</div>

A method I’ve used before is:

```plaintext
PluginStoreRow.where("value::json->>'provider'=?", provider)

```

There is no need for the database column to actually be set to json for that to work. ([see here](https://www.postgresql.org/docs/9.3/static/datatype-json.html)).

The other thing I’ve used to help with JSON in plugins is `ActiveRecord::Store`. It allows storing data in json, while keeping all the activerecord validation/serialization magic.

> <https://github.com/discourse/discourse-chat-integration/blob/main/app/models/channel.rb#L3>

Switching to jsonb would certainly be more performant for looking up values - I like the idea of adding an additional column, so that we don’t break existing plugins. If we add jsonb, it looks like activerecord has good support for it as well 🙂

---

_[View the full topic](https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418)._
