Using PostgreSQL, how do I manage a sequence (auto incremented Integer id) for the following scenario-
Table named 'businesses' which has 'id' and some more columns.
Table named 'users' which has:
a composite primary key, composed of a 'business_id', and an 'id', and have the 'id' reset it's counting for each 'business_id' when I insert now rows.
a simple column 'name'.
something like having a separate sequence per business.
Example
When I run the following queries:
insert into users (business_id, name) values (1, 'a')
insert into users (business_id, name) values (2, 'b')
insert into users (business_id, name) values (1, 'c')
I want to end up with the following 'users' table:
business_id, id, name
1, 1, 'a'
1, 2, 'c'
2, 1, 'b'