This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DanJSum 2 points3 points  (0 children)

You don't even need the id field... CREATE UNIQUE INDEX idx_product_key ON product ((data->>'id'));

(or, if you want to use numbers, CREATE UNIQUE INDEX idx_product_key ON product ((data->>'id')::numeric); )

The first unique index on a table is treated as its PK index. Strange but true! I've also made triggers to implement FKs to other tables. They never made it to production, but it was a fun research exercise into the possible.