【问题标题】:Select rows from array of uuid when dealing with two tables处理两个表时从 uuid 数组中选择行
【发布时间】:2022-01-12 17:53:27
【问题描述】:

我有产品和供应商。每个产品都有一个 uuid,每个供应商都有一个他们可以提供的产品的 uuid 列表。 如何选择给定(即通过提供者 uuid)提供者可以提供的所有产品?

Products:
    +------+------+------+
    | uuid | date | name |
    +------+------+------+
    |    0 |    - |    - |
    |    1 |    - |    - |
    |   2  |    - |    - |
    +------+------+------+
Providers:
+------+----------------+
| uuid | array_products |
+------+----------------+
|    0 | [...]          |
|    1 | [...]          |
|   2  | [...]          |
+------+----------------+

【问题讨论】:

  • array_products的数据类型是什么?

标签: node.js postgresql express


【解决方案1】:
select p.name, u.product_uuid 
from products p
join
(
 select unnest(array_products) as product_uuid 
 from providers where uuid = :target_provider_uuid 
) u on p.uuid = u.product_uuid;

但请注意,您的数据设计效率不高,而且比标准化设计更难处理。

【讨论】:

    猜你喜欢
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 2021-12-14
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多