Ask A Question


You’re not receiving notifications from this thread.

Is it good practice to use array/jsonb column for a non searchable, single row table?

Luca Rossi asked in Rails

Hi guys wanted to get some feedback on the way I have been using In my first app I am using both array (text) and jsonb columns. I am using these instead of additional DB tables since the structure in each record will be different and I do not intend to search into them.

The array text column is used to:

  • store operating hours for each store
  • store consultation appointment time slots (min length is 15 = 1 slot, so a 1 hour consultation = 4 slots). I am storing an array with the slot numbers as I need all slots when I calculate the available timeslots for new consultations (all slots - busy slots = available slots)

The JSONB columns are used to manage form templates and values:
One columns is used to store form templates created using formbuilder.js in the tforms table. The other is used to store both form and data in the actual consultation table: when a consultation is created, the template from the forms table is saved to the consultation form column. From this point on every time the consultation is accessed the form and inputs are accessed/saved in the local column. This way the form template can be modified for future consultations and the old data is preserved (i need to add a function that allows users to add newly added fields to existing consultations if required).

All works fine for now on the prototype. However, I wonder if anyone would have done things in a different way..

Thanks in advance for your time!


Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,453+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.