我想生成一系列数字(例如从0到50)并使用这个系列作为PostgreSQL中get_raw_page()函数的参数。
select count(*) as record_count
from heap_page_items(get_raw_page('test_table', generate_series(0,10)));
问题是get_raw_page()不接受表作为参数。如何使用数字表作为get_raw_page()的参数?
ERROR: set-valued function called in context that cannot accept a set
答案 0 :(得分:1)
select (
select count(*)
from heap_page_items(get_raw_page('test_table', i))
) as record_count
from generate_series(0,10) s(i)
如果使用版本9.3 +
,则为横向连接select count(*) as record_count
from
generate_series(0,10) s(i)
left join lateral
heap_page_items(get_raw_page('test_table', s.i)) on true