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
Re: unique index on embedded json object |
| Список | 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)
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
Thanks,
Jason
В списке pgsql-general по дате отправления: