1SELECT size, pg_size_pretty(size), pg_size_pretty(-1 * size) FROM 2 (VALUES (10::bigint), (1000::bigint), (1000000::bigint), 3 (1000000000::bigint), (1000000000000::bigint), 4 (1000000000000000::bigint)) x(size); 5 6SELECT size, pg_size_pretty(size), pg_size_pretty(-1 * size) FROM 7 (VALUES (10::numeric), (1000::numeric), (1000000::numeric), 8 (1000000000::numeric), (1000000000000::numeric), 9 (1000000000000000::numeric), 10 (10.5::numeric), (1000.5::numeric), (1000000.5::numeric), 11 (1000000000.5::numeric), (1000000000000.5::numeric), 12 (1000000000000000.5::numeric)) x(size); 13 14-- test where units change up 15SELECT size, pg_size_pretty(size), pg_size_pretty(-1 * size) FROM 16 (VALUES (10239::bigint), (10240::bigint), 17 (10485247::bigint), (10485248::bigint), 18 (10736893951::bigint), (10736893952::bigint), 19 (10994579406847::bigint), (10994579406848::bigint), 20 (11258449312612351::bigint), (11258449312612352::bigint)) x(size); 21 22SELECT size, pg_size_pretty(size), pg_size_pretty(-1 * size) FROM 23 (VALUES (10239::numeric), (10240::numeric), 24 (10485247::numeric), (10485248::numeric), 25 (10736893951::numeric), (10736893952::numeric), 26 (10994579406847::numeric), (10994579406848::numeric), 27 (11258449312612351::numeric), (11258449312612352::numeric)) x(size); 28 29-- pg_size_bytes() tests 30SELECT size, pg_size_bytes(size) FROM 31 (VALUES ('1'), ('123bytes'), ('1kB'), ('1MB'), (' 1 GB'), ('1.5 GB '), 32 ('1TB'), ('3000 TB'), ('1e6 MB')) x(size); 33 34-- case-insensitive units are supported 35SELECT size, pg_size_bytes(size) FROM 36 (VALUES ('1'), ('123bYteS'), ('1kb'), ('1mb'), (' 1 Gb'), ('1.5 gB '), 37 ('1tb'), ('3000 tb'), ('1e6 mb')) x(size); 38 39-- negative numbers are supported 40SELECT size, pg_size_bytes(size) FROM 41 (VALUES ('-1'), ('-123bytes'), ('-1kb'), ('-1mb'), (' -1 Gb'), ('-1.5 gB '), 42 ('-1tb'), ('-3000 TB'), ('-10e-1 MB')) x(size); 43 44-- different cases with allowed points 45SELECT size, pg_size_bytes(size) FROM 46 (VALUES ('-1.'), ('-1.kb'), ('-1. kb'), ('-0. gb'), 47 ('-.1'), ('-.1kb'), ('-.1 kb'), ('-.0 gb')) x(size); 48 49-- invalid inputs 50SELECT pg_size_bytes('1 AB'); 51SELECT pg_size_bytes('1 AB A'); 52SELECT pg_size_bytes('1 AB A '); 53SELECT pg_size_bytes('9223372036854775807.9'); 54SELECT pg_size_bytes('1e100'); 55SELECT pg_size_bytes('1e1000000000000000000'); 56SELECT pg_size_bytes('1 byte'); -- the singular "byte" is not supported 57SELECT pg_size_bytes(''); 58 59SELECT pg_size_bytes('kb'); 60SELECT pg_size_bytes('..'); 61SELECT pg_size_bytes('-.'); 62SELECT pg_size_bytes('-.kb'); 63SELECT pg_size_bytes('-. kb'); 64 65SELECT pg_size_bytes('.+912'); 66SELECT pg_size_bytes('+912+ kB'); 67SELECT pg_size_bytes('++123 kB'); 68