首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >具有多个配置文件的用户的PostgreSQL模型

具有多个配置文件的用户的PostgreSQL模型
EN

Stack Overflow用户
提问于 2018-06-08 03:46:08
回答 2查看 342关注 0票数 0

一个用户可以有3种类型的配置文件: A、B、C

对于每种类型的配置文件,用户可以具有不同的名称、照片集和描述。

这应该如何建模?

  • 主要由一种类型一次获取,例如获取用户的A配置文件
  • 字段不进行过滤例如无过滤where name =
  • 无角色/权限担心
  • UI允许用户一次更新配置文件的名称或照片或说明

在单个表中分隔列:

profile
---
name_A name_B name_C photos_A photos_B photos_C description_A description_B description_C

加入另一个表:

profile
---
A_profile_id B_profile_id C_profile_id

A_profile
---
id name photos description

B_profile
---
id name photos description

C_profile
---
id name photos description

jsonb按字段:

profile
---
name{A,B,C} photos{A,B,C} description{A,B,C}

jsonb按配置文件类型:

profile
---
A_profile{name,photos,description} B_profile{name,photos,description} C_profile{name,photos,description}

嵌套的jsonb (试探性...):

profile
---
profile{A{name,photos,description},B{name,photos,description},C{name,photos,description}}
EN

回答 2

Stack Overflow用户

发布于 2018-06-08 04:21:21

如果你打算有一组固定的不同的配置文件,那么利用关系数据库的优势,你应该选择"Join Another Table“选项。

其他每个选项都稍微更灵活一些,但本质上只是一个非规范化的版本。

票数 1
EN

Stack Overflow用户

发布于 2018-06-08 04:57:17

假设所有的配置文件都是相同的,那么我首先想到的是两个表:

create table Profiles (
    profileId serial,
    . . .
);

create table Persons (
   personId serial,
   . . .
   profile_A int references profiles(profileId),
   profile_B int references profiles(profileId),
   profile_C int references profiles(profileId)
);

尽管有三个不同的列可能有很好的理由,但您可能还需要一个连接表:

create table personProfiles (
    personProfileId serial,
    personId int references person(personId),
    profileId int references profiles(profileId),
    profileTye <whatever>
);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50749142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档