jsonb vs jsonb[] for multiple addresses for a customer

你离开我真会死。 提交于 2019-11-27 16:19:29

Use a jsonb (not jsonb[]!) column with the structure like this:

select
'[{
        "adresse_line-1": "a11",
        "adresse_line-2": "a12",
        "postalcode": "code1"
    },
    {
        "adresse_line-1": "a21",
        "adresse_line-2": "a22",
        "postalcode": "code2"
    }
]'::jsonb;

Though, a regular table related to the main one is a better option.

Why not jsonb[]? Take a look at JSON definition:

JSON is built on two structures:

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

In a jsonb column you can therefore store an array of objects. Attempts to use the array of jsonb are probably due to misunderstanding of this type of data. I have never seen a reasonable need for such a solution.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!