I want to get this result in my table contacts
:
|contact_id | user_id | user_contact_id |
+-----------+------------------+----------------------+
| 1 | 1 | 1 |
+-----------+------------------+----------------------+
| 2 | 1 | 2 |
+-----------+------------------+----------------------+
| 3 | 1 | 3 |
+-----------+------------------+----------------------+
| 4 | 2 | 1 |
+-----------+------------------+----------------------+
| 5 | 2 | 2 |
+-----------+------------------+----------------------+
| 6 | 2 | 3 |
+-----------+------------------+----------------------+
| 7 | 3 | 1 |
+-----------+------------------+----------------------+
I'm going to insert only user_id
.
INSERT INTO contacts (user_id) VALUES ($user_id);
The contact_id
will auto-increment because it's a serial
. I want user_contact_id
to also populate automatically by the DB itself, so it is 100% stable with concurrent writes.