Before Postgres 8.4 there is no built-in way to get a percentage of rows with a single query. Consider this closely related thread on the pgsql-sql list
You could write a function doing the work in a single call. this should work in Postgres 8.3:
CREATE OR REPLACE FUNCTION foo(_pct int)
RETURNS SETOF v_t AS
$func$
DECLARE
_ct int := (SELECT count(*) FROM v_t);
_offset int := (_ct * $1) / 100;
_limit int := (_ct * (100 - 2 * $1)) / 100;
BEGIN
RETURN QUERY
SELECT *
FROM v_t
OFFSET _offset
LIMIT _limit;
END
$func$ LANGUAGE plpgsql;
Call:
SELECT * FROM foo(5)
This actually crops 5% from top and bottom.
The return type RETURNS SETOF v_t
is derived from a view named v_t
directly.