-- Function to generate a long string CREATE OR REPLACE FUNCTION string_long(length integer) RETURNS text AS $$ DECLARE result text := ''; i integer := 0; BEGIN if length < 0 then raise exception 'Given length cannot be less than 0'; end if; for i in 1..length loop result := result || 'X'; end loop; return result; END; $$ LANGUAGE plpgsql IMMUTABLE; -- Some data CREATE TABLE aa (a int, b text); ALTER TABLE aa ALTER COLUMN b SET STORAGE EXTERNAL; INSERT INTO aa values (generate_series(1, 100000), string_long(4000)); SELECT * FROM aa WHERE a = 14000; -- DROP TABLE aa;