email -----+------------------------------------------ 1 (Postgres)

问题描述 投票:0回答:3

基本上我的用户有一个动态属性表。简化后的表,我想做的是一个SELECT,返回列user_id, city, region,其中city & region不为空。

SELECT * FROM users;
 id  |                  email                   
-----+------------------------------------------
  1 | [email protected]


SELECT * FROM user_attributes;
 id |      name      
----+----------------
  1 | Salutation
  2 | Given Name
  3 | Surname
  4 | Alias
  5 | Address
  6 | Address 2
  7 | Address 3
  8 | City
  9 | Region
....

SELECT * FROM user_attribute_values;
 client_id | attribute_id | value 
-----------+--------------+-------

我想做的是一个SELECT,返回列 user_id, city, region,其中 city & region 不是空的。

建立user_attributes表的原因是,人们可能想存储任何数量的关于用户的自定义字段,而事先不可能知道它们是什么,将它们创建为用户表的列。

sql postgresql database-design entity-attribute-value
3个回答
© www.soinside.com 2019 - 2024. All rights reserved.