rfu*_*sca 15
不知道你为什么要做这样的事情,但......
CREATE TABLE testy (a int,b text);
INSERT INTO testy VALUES (3,'test');
SELECT testy.*,generate_series(1,a) from testy; --returns 3 rows
Run Code Online (Sandbox Code Playgroud)
您可以使用递归查询来完成此操作,请查看postgresql 文档中的示例 。
就像是
WITH RECURSIVE t(cnt, id, field2, field3) AS (
SELECT 1, id, field2, field3
FROM foo
UNION ALL
SELECT t.cnt+1, t.id, t.field2, t.field3
FROM t, foo f
WHERE t.id = f.id and t.cnt < f.repeat_cnt
)
SELECT id, field2, field3 FROM t;
Run Code Online (Sandbox Code Playgroud)