0

Let's say that I have this table :

CREATE TABLE test (
  id uuid unique default uuid_generate_v4(),
  version int,
  another_column text,
  PRIMARY KEY (id, version)
);

What I want to achieve is, when I insert new row, I want the version to be based on id column. Ex :

+--------------------------------------+---------+
|                  id                  | version |
+--------------------------------------+---------+
| 25d57091-4d11-40de-9ca7-2c9500eb5484 |       1 |
| 25d57091-4d11-40de-9ca7-2c9500eb5484 |       2 |
| 25d57091-4d11-40de-9ca7-2c9500eb5484 |       3 |
| 9b43eed3-92fd-40e1-9bb4-9220f6bbd7f5 |       1 |
| 9b43eed3-92fd-40e1-9bb4-9220f6bbd7f5 |       2 |
+--------------------------------------+---------+

So I though about creating a sequence but couldn't find anything on this in the manual to base the nextval on a column value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.