Surrogate key resolution, or what am I missing in the Surrogate v Natural argument?
A proper Postgres schema for your example could look like this:

CREATE TABLE selected_task(
  selected_task_id serial PRIMARY KEY  -- surrogate PK
, user_id          int REFERENCES users(user_id)
, task_number      int
, name             text
, jobsite_id       int REFERENCES site(jobsite_id)
);

CREATE TABLE sub_task(
  sub_task_id      serial PRIMARY KEY
, selected_task_id int REFERENCES selected_task  -- this is how
, assignee         int REFERENCES users(assignee)
, time_allowed     int
, report_to        int REFERENCES groups(report_to)
);



Use a serial column as surrogate PK.


PostgreSQL SELECT primary key as &quot;serial&quot; or &quot;bigserial&quot;
Auto increment SQL function
Use serial ID for multiple columns and return it from INSERT

You can't use reserved words like user or group as identifier.
Some other improvements. Detailed instructions here:


How to implement a many-to-many relationship in PostgreSQL?



INSERT in both tables at the same time?

Use a data-modifying CTE with the RETURNING clause, or two INSERT statements in a transaction with lastval() (which is the Postgres equivalent for SCOPE_IDENTITY() in SQL server @Aaron mentioned in his comment):

Related answer with code example for either method.


Inserting into related tables