-- -- LIMIT -- Check the LIMIT/OFFSET feature of SELECT --
SELECT''::text AS two, unique1, unique2, stringu1 FROM onek WHERE unique1 > 50 ORDERBY unique1 LIMIT2; SELECT''::text AS five, unique1, unique2, stringu1 FROM onek WHERE unique1 > 60 ORDERBY unique1 LIMIT5; SELECT''::text AS two, unique1, unique2, stringu1 FROM onek WHERE unique1 > 60AND unique1 < 63 ORDERBY unique1 LIMIT5; SELECT''::text AS three, unique1, unique2, stringu1 FROM onek WHERE unique1 > 100 ORDERBY unique1 LIMIT3 OFFSET 20; SELECT''::text AS zero, unique1, unique2, stringu1 FROM onek WHERE unique1 < 50 ORDERBY unique1 DESCLIMIT8 OFFSET 99; SELECT''::text AS eleven, unique1, unique2, stringu1 FROM onek WHERE unique1 < 50 ORDERBY unique1 DESCLIMIT20 OFFSET 39; SELECT''::text AS ten, unique1, unique2, stringu1 FROM onek ORDERBY unique1 OFFSET 990; SELECT''::text AS five, unique1, unique2, stringu1 FROM onek ORDERBY unique1 OFFSET 990LIMIT5; SELECT''::text AS five, unique1, unique2, stringu1 FROM onek ORDERBY unique1 LIMIT5 OFFSET 900;
-- Test null limit and offset. The planner would discard a simple null -- constant, so to ensure executor is exercised, do this: select * from int8_tbl limit (casewhen random() < 0.5thennull::bigint end); select * from int8_tbl offset (casewhen random() < 0.5thennull::bigint end);
-- Test assorted cases involving backwards fetch from a LIMIT plan node
begin;
-- Stress test for variable LIMIT in conjunction with bounded-heap sorting
SELECT
(SELECT n FROM (VALUES (1)) AS x,
(SELECT n FROM generate_series(1,10) AS n ORDERBY n LIMIT1 OFFSET s-1) AS y) AS z FROM generate_series(1,10) AS s;
-- -- Test behavior of volatile and set-returning functions in conjunction -- with ORDER BY and LIMIT. --
select unique1, unique2, generate_series(1,10) from tenk1 orderby tenthous limit7;
-- use of random() is to keep planner from folding the expressions together explain (verbose, costs off) select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2;
select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2;
explain (verbose, costs off) select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2 orderby s2 desc;
select generate_series(0,2) as s1, generate_series((random()*.1)::int,2) as s2 orderby s2 desc;
-- test for failure to set all aggregates' aggtranstype explain (verbose, costs off) select sum(tenthous) as s1, sum(tenthous) + random()*0as s2 from tenk1 groupby thousand orderby thousand limit3;
select sum(tenthous) as s1, sum(tenthous) + random()*0as s2 from tenk1 groupby thousand orderby thousand limit3;
-- -- FETCH FIRST -- Check the WITH TIES clause --
SELECT thousand FROM onek WHERE thousand < 5 ORDERBY thousand FETCH FIRST 2 ROW WITH TIES;
SELECT thousand FROM onek WHERE thousand < 5 ORDERBY thousand FETCH FIRST ROWS WITH TIES;
SELECT thousand FROM onek WHERE thousand < 5 ORDERBY thousand FETCH FIRST 1 ROW WITH TIES;
SELECT thousand FROM onek WHERE thousand < 5 ORDERBY thousand FETCH FIRST 2 ROW ONLY;
-- SKIP LOCKED and WITH TIES are incompatible SELECT thousand FROM onek WHERE thousand < 5 ORDERBY thousand FETCH FIRST 1 ROW WITH TIES FORUPDATE SKIP LOCKED;
-- should fail SELECT''::text AS two, unique1, unique2, stringu1 FROM onek WHERE unique1 > 50 FETCH FIRST 2 ROW WITH TIES;
-- test ruleutils CREATE VIEW limit_thousand_v_1 ASSELECT thousand FROM onek WHERE thousand < 995 ORDERBY thousand FETCH FIRST 5 ROWS WITH TIES OFFSET 10;
\d+ limit_thousand_v_1 CREATE VIEW limit_thousand_v_2 ASSELECT thousand FROM onek WHERE thousand < 995 ORDERBY thousand OFFSET 10FETCH FIRST 5 ROWS ONLY;
\d+ limit_thousand_v_2 CREATE VIEW limit_thousand_v_3 ASSELECT thousand FROM onek WHERE thousand < 995 ORDERBY thousand FETCH FIRST NULL ROWS WITH TIES; -- fails CREATE VIEW limit_thousand_v_3 ASSELECT thousand FROM onek WHERE thousand < 995 ORDERBY thousand FETCH FIRST (NULL+1) ROWS WITH TIES;
\d+ limit_thousand_v_3 CREATE VIEW limit_thousand_v_4 ASSELECT thousand FROM onek WHERE thousand < 995 ORDERBY thousand FETCH FIRST (5::bigint) ROWS WITH TIES;
\d+ limit_thousand_v_4 CREATE VIEW limit_thousand_v_5 ASSELECT thousand FROM onek WHERE thousand < 995 ORDERBY thousand FETCH FIRST NULL ROWS ONLY;
\d+ limit_thousand_v_5 -- leave these views
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.