I'm trying to create a table as follows:
CREATE TABLE SCHEDULE (
SESSIONID SERIAL,
MODULECODE VARCHAR(10),
CONSTRAINT SCHEDULE_FOREIGN_KEY FOREIGN KEY (MODULECODE) REFERENCES MODULES (MODULECODE),
CONSTRAINT SCHEDULE_PRIMARY_KEY PRIMARY KEY (SESSIONID, MODULECODE));
The idea being that SESSION ID would auto increment with each new row but only local to MODULECODE, for example:
----------------------
|SESSIONID|MODULECODE|
|---------|----------|
| 1 | A |
| 2 | A |
| 3 | A |
| 1 | B |
| 2 | B |
| 1 | C |
| 2 | C |
|--------------------|
I believe this is how AUTO_INCREMENT functions in MySQL but I suspect PostgreSQL doesn't work this way. How else would I achieve this in PostgreSQL?
serialtype. It would be a lot easier if you generate those numbers when displaying the data e.g. usingrow_number()and just keep thesessionidas an overall unique value.