unique index on embedded json object

Поиск
Список
Период
Сортировка
От Lee Jason
Тема unique index on embedded json object
Дата
Msg-id SNT151-W958134DD9A06AB822BE1AED0B20@phx.gbl
обсуждение исходный текст
Ответы Re: unique index on embedded json object  (John R Pierce <pierce@hogranch.com>)
Re: unique index on embedded json object  (Peter Geoghegan <peter.geoghegan86@gmail.com>)
Список pgsql-general
Hi forks,

I am testing postgresql 9.4 beta2 right now.  I am wondering if it is possible to create a unique index on embedded json object?

For example,

I create a table names "products"

CREATE TABLE products (oid serial primary key, data jsonb)

Now, I try to insert json object into data column.

{"id": "12345",
"bags": [{
    "sku": "abc123",
    "price": 0,
},
{
    "sku": "abc123",
    "price": 0,
}]
}

However, I want sku of bags to be unique.  It means the json can't be inserted into products tables because sku is not unique in this case.  

I tried to create a unique index like below, but it failed.

CREATE UNIQUE INDEX product_sku_index ON products( (data->'bags'->'sku') )

Any suggestions, please?  Thank you.

Thanks,
Jason

В списке pgsql-general по дате отправления:

Предыдущее
От: Eric Smith
Дата:
Сообщение: Re: can't restore database created with pg_dump
Следующее
От: John R Pierce
Дата:
Сообщение: Re: unique index on embedded json object