Hello,

I am creating a simple database and I have never worked with Postgres arrays before, so I just have a quick question.

So I have to tables: Class and Student

Class has a unique ID and contains several Students.

Student has a unique ID and can also be taking several classes.
So I'm trying to decide where I should implement this as a separate weak entity or to use arrays.

So one option would be this:
Code:
CREATE TABLE Class(
 ID serial PRIMARY KEY
);
CREATE TABLE Student(
 ID serial PRIMARY KEY
 username varchar(20),
);
CREATE TABLE Enrolled(
 class_id int REFERENCES Class(ID),
 stud_id int REFERENCES Student(ID)
);
Or I could use this method with arrays:
Code:
CREATE TABLE Class(
 ID serial PRIMARY KEY
);
CREATE TABLE Student(
 ID serial PRIMARY KEY,
 username varchar(20),
 classes int[5]
);

My question is which one would be better/faster to search. I'm probably more concerned with speed than space at this point. So for example if I want to get a list of all the students usernames in a class would it be better/faster to search the Student classes array for a class ID in the second method, or would it be better/faster to search through the enrollment table from example one?