0

I have a database which contains 2 tables - tests and questions(for those tests). enter image description here

Questions table has a column called right_answer which might be an array of strings or a single string. enter image description here

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?

4
  • Sample data is better presented as formatted text. See here for some tips on how to create nice looking tables. Commented Mar 14, 2020 at 10:58
  • @a_horse_with_no_name thanks, but it doesn`t answer my question Commented Mar 14, 2020 at 11:11
  • Nevertheless: you should not post code as images Commented Mar 14, 2020 at 11:21
  • @a_horse_with_no_name okay, got it. Commented Mar 14, 2020 at 11:25

1 Answer 1

2

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
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.