有谁知道如何在PostgreSQL中扩展频率表?
例如,变换表x:
data | frequency -------+----------- string | 4
进入
data | index -------+------- string | 1 string | 2 string | 3 string | 4
设置代码:
CREATE TABLE x ( data TEXT, frequency INTEGER ); INSERT INTO x VALUES ('string',4);
这非常简单generate_series():
generate_series()
SELECT data, generate_series(1, frequency) AS index FROM x;