使用 Greenplum 6(基于 PostgreSQL 9.4),我有这些 样品表:
桌子
SAMPLE_A
:
| uniqueId | SampleSz |
| -------- | -------- |
| 1 | 25 |
| 2 | 50450 |
| 3 | 9 |
桌子
SAMPLE_B
:
| IP | uniqueId |
| -------- | -------- |
| 1.4.4.5 | (1,2,3) |
| 2.5.6.7 | (2) |
| 3.4.7.8 | (1,3) |
我正在尝试从上面创建一个新表:
对于
uniqueId=1
,拉取一组随机的25(SAMPLE_A.SampleSz
)个IP(SAMPLE_B.IP
),其中SAMPLE_A.uniqueId
在SAMPLE_B.uniqueId
的数组中。然后迭代到下一个SAMPLE_A.uniqueId
并随机拉取50450 ...等我试图为一个单一的记录写这篇文章(但失败了):
select i.ip, s.uniqueId
from SAMPLE_A s
join lateral (
select distinct ip
from SAMPLE_B i
where s.uniqueId = any(i.uniqueId)
-- ORDER BY random()
LIMIT s.SampleSz
) i on true
这会抛出一个解组错误。即使有效,也不能解决我的全部问题,但我认为这是第一步。