CREATE UNLOGGED TABLE t (id INT PRIMARY KEY, filler TEXT);

-- Text and CSV, no special characters
INSERT INTO t
SELECT s, repeat('A', 4096)
FROM generate_series(1, 100000) AS s;
COPY t TO '~/coding/postgres/t_4096_none.txt' (FORMAT text);
COPY t TO '~/coding/postgres/t_4096_none.csv' (FORMAT csv, QUOTE '"');

-- Text, with ~1/3 escapes (\)
TRUNCATE t;
INSERT INTO t
SELECT s, repeat('A\A', 1365) -- 1365 * 3 = 4095 bytes, 1365 \ chars
FROM generate_series(1, 100000) AS s;
COPY t TO '~/coding/postgres/t_4096_escape.txt' (FORMAT text);

-- CSV, with ~1/3 quotes (")
TRUNCATE t;
INSERT INTO t
SELECT s, repeat('A"A', 1365) -- 1365 * 3 = 4095 bytes, 1365 " chars
FROM generate_series(1, 100000) AS s;
COPY t TO '~/coding/postgres/t_4096_quote.csv' (FORMAT csv, QUOTE '"');

DROP TABLE t;