Reputation: 590
I have a database which contains 2 tables - tests and questions(for those tests).
Questions table has a column called right_answer which might be an array of strings or a single string.
So, I'm wondering what is the best approach to store data in this case? Should I have several questions tables for an each answer type or there's some other way?
Maybe I can store my right_answer
using only one table somehow?
Upvotes: 0
Views: 394
Reputation:
A properly normalized model should always be your first approach:
create table questions
(
id integer generated always as identity primary key,
type text not null,
test_id bigint references tests
);
create table answers
(
id integer generated always as identity primary key,
question_id integer not null references questions,
answer text not null,
is_right_answer boolean not null
);
Upvotes: 2