I have a table called student with the below columns as shown below
S_id, person_id, subject_id, start_date, end_date, count
While, I have written a query to extract data from other tables to feed it into the person table
The query that I wrote looks like below
INSERT INTO student (S_id, person_id, subject_id, start_date, end_date, count)
SELECT
person_id
, subject_id,
, MIN(exam_start_date) AS start_date
, end_date
, COUNT(*) AS count
FROM main_table
GROUP BY person_id, subject_id, end_date
ORDER BY person_id, subject_id
As you can see my select query fetches data only from person_id and for other columns.
How can I create an autoincrement or serial for the S_id column in the select statement so I can insert the data?
Currently, I receive an error
ERROR: null value in column "S_id" violates not-null constraint DETAIL: Failing row contains (null, 1234, 77670, 2139-04-22, 2139-04-22, 1).
S_idcolumn is declaredSERIALjust omit it from theINSERTlist.