I want a table, where for every new id, the 2nd id(e.g. revision) starts from 1, such as:
id revision data
1 1 data1
1 2 data2
2 1 data3
2 2 data4
1 3 data5
3 1 data6
When I want to update the data(the row), I keep the original row, and create a new row with the same id, but with different revision. So I keep track of changes done on the table.
I create the table with this query:
create table my_table (
id serial not null,
revision serial not null,
data jsonb not null
primary key(id, revision)
);
However, with this query, revision continues from just where it left, such as: id revision data
1 1 data1
1 2 data2
2 3 data3
2 4 data4
1 5 data5
3 6 data6
How can I achieve such a table structure?