一列中的 PostgreSQL 不同数据类型

PostgreSQL different datatypes in one column

我有一个数据库,其中包含 2 tables - 测试和问题(对于那些测试)。

问题 table 有一个名为 right_answer 的列,它可能是一个 字符串数组 单串

那么,我想知道在这种情况下存储数据的最佳方法是什么?对于每个答案类型,我应该有几个问题 table 还是有其他方法?

也许我可以只用一个 table 存储我的 right_answer

正确规范化的模型应该始终是您的首选方法:

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
);