Skip to content Skip to sidebar Skip to footer

Storing Dynamic Properties Of Objects In Sql

I am trying to store 'dynamic' properties about objects in SQL. As an example, let's say I have a table called objs that has two columns (id, name). Now some users may want to stor

Solution 1:

This has been discussed repeatedly before:

The short version: EAV has its place, but it's often better to use json, XML, or hstore. PostgreSQL 9.4's enhanced json will probably become the most attractive choice, as it combines the advantages of json and hstore.

Solution 2:

First, you should start with a proper database schema (using standard data model patterns) so you can avoid this as much as possible.

Martin Fowler recommends using either a serialized LOB (such as JSON or XML), or allowing the user to edit their own database schema (which is my preferred method):

http://martinfowler.com/bliki/UserDefinedField.html

Bill Karwin has a post somewhere on creating a second table to index values in the blob field, but I can't find it right now. Will post when I do.

Post a Comment for "Storing Dynamic Properties Of Objects In Sql"