CREATE EXTENSION varint; -- Basic type comparison tests for varint64 SELECT '64'::VARINT64 = '64'::VARINT64 AS t; t --- t (1 row) SELECT '0'::VARINT64 = '1'::VARINT64 AS f; f --- f (1 row) SELECT '64'::VARINT64 <> '64'::VARINT64 AS f; f --- f (1 row) SELECT '0'::VARINT64 <> '1'::VARINT64 AS t; t --- t (1 row) SELECT '-1'::VARINT64 < '64'::VARINT64 AS t; t --- t (1 row) SELECT '-256'::VARINT64 < '256'::VARINT64 AS t; t --- t (1 row) SELECT '64'::VARINT64 < '64'::VARINT64 AS f; f --- f (1 row) SELECT '64'::VARINT64 < '63'::VARINT64 AS f; f --- f (1 row) SELECT '1024'::VARINT64 < '-4096'::VARINT64 AS f; f --- f (1 row) SELECT '-1'::VARINT64 <= '64'::VARINT64 AS t; t --- t (1 row) SELECT '-256'::VARINT64 <= '256'::VARINT64 AS t; t --- t (1 row) SELECT '64'::VARINT64 <= '64'::VARINT64 AS t; t --- t (1 row) SELECT '64'::VARINT64 <= '63'::VARINT64 AS f; f --- f (1 row) SELECT '1024'::VARINT64 <= '-4096'::VARINT64 AS f; f --- f (1 row) SELECT '-1'::VARINT64 > '64'::VARINT64 AS f; f --- f (1 row) SELECT '-256'::VARINT64 > '256'::VARINT64 AS f; f --- f (1 row) SELECT '64'::VARINT64 > '64'::VARINT64 AS f; f --- f (1 row) SELECT '64'::VARINT64 > '63'::VARINT64 AS t; t --- t (1 row) SELECT '1024'::VARINT64 > '-4096'::VARINT64 AS t; t --- t (1 row) SELECT '-1'::VARINT64 >= '64'::VARINT64 AS f; f --- f (1 row) SELECT '-256'::VARINT64 >= '256'::VARINT64 AS f; f --- f (1 row) SELECT '64'::VARINT64 >= '64'::VARINT64 AS t; t --- t (1 row) SELECT '64'::VARINT64 >= '63'::VARINT64 AS t; t --- t (1 row) SELECT '1024'::VARINT64 >= '-4096'::VARINT64 AS t; t --- t (1 row) -- varint64 <=> {int2,int4,int8} conversion tests SELECT '0'::VARINT64::INT2 AS "0"; 0 --- 0 (1 row) SELECT '0'::INT2::VARINT64 AS "0"; 0 --- 0 (1 row) SELECT '32767'::INT2::VARINT64 AS "32767"; 32767 ------- 32767 (1 row) SELECT '32767'::VARINT64::INT2 AS "32767"; 32767 ------- 32767 (1 row) SELECT '-32768'::INT2::VARINT64 AS "-32768"; -32768 -------- -32768 (1 row) SELECT '-32768'::VARINT64::INT2 AS "-32768"; -32768 -------- -32768 (1 row) SELECT '32768'::INT2::VARINT64 AS "ERROR: 32768"; ERROR: value "32768" is out of range for type smallint LINE 1: SELECT '32768'::INT2::VARINT64 AS "ERROR: 32768"; ^ SELECT '32768'::VARINT64::INT2 AS "ERROR: 32768"; ERROR: integer out of range SELECT '-32769'::INT2::VARINT64 AS "ERROR: -32769"; ERROR: value "-32769" is out of range for type smallint LINE 1: SELECT '-32769'::INT2::VARINT64 AS "ERROR: -32769"; ^ SELECT '-32769'::VARINT64::INT2 AS "ERROR: -32769"; ERROR: integer out of range SELECT '0'::VARINT64::INT4 AS "0"; 0 --- 0 (1 row) SELECT '0'::INT4::VARINT64 AS "0"; 0 --- 0 (1 row) SELECT '2147483647'::INT4::VARINT64 AS "2147483647"; 2147483647 ------------ 2147483647 (1 row) SELECT '2147483647'::VARINT64::INT4 AS "2147483647"; 2147483647 ------------ 2147483647 (1 row) SELECT '-2147483648'::INT4::VARINT64 AS "-2147483648"; -2147483648 ------------- -2147483648 (1 row) SELECT '-2147483648'::VARINT64::INT4 AS "-2147483648"; -2147483648 ------------- -2147483648 (1 row) SELECT '2147483648'::INT4::VARINT64 AS "ERROR: 2147483648"; ERROR: value "2147483648" is out of range for type integer LINE 1: SELECT '2147483648'::INT4::VARINT64 AS "ERROR: 2147483648"... ^ SELECT '2147483648'::VARINT64::INT4 AS "ERROR: 2147483648"; ERROR: integer out of range SELECT '-2147483649'::INT4::VARINT64 AS "ERROR: -2147483649"; ERROR: value "-2147483649" is out of range for type integer LINE 1: SELECT '-2147483649'::INT4::VARINT64 AS "ERROR: -2147483649... ^ SELECT '-2147483649'::VARINT64::INT4 AS "ERROR: -2147483649"; ERROR: integer out of range SELECT '0'::VARINT64::INT8 AS "0"; 0 --- 0 (1 row) SELECT '0'::INT8::VARINT64 AS "0"; 0 --- 0 (1 row) SELECT '9223372036854775807'::INT8::VARINT64 AS "9223372036854775807"; 9223372036854775807 --------------------- 9223372036854775807 (1 row) SELECT '9223372036854775807'::VARINT64::INT8 AS "9223372036854775807"; 9223372036854775807 --------------------- 9223372036854775807 (1 row) SELECT '-9223372036854775808'::INT8::VARINT64 AS "-9223372036854775808"; -9223372036854775808 ---------------------- -9223372036854775808 (1 row) SELECT '-9223372036854775808'::VARINT64::INT8 AS "-9223372036854775808"; -9223372036854775808 ---------------------- -9223372036854775808 (1 row) SELECT '9223372036854775808'::INT8::VARINT64 AS "ERROR: 9223372036854775808"; ERROR: value "9223372036854775808" is out of range for type bigint LINE 1: SELECT '9223372036854775808'::INT8::VARINT64 AS "ERROR: 92... ^ SELECT '9223372036854775808'::VARINT64::INT8 AS "ERROR: 9223372036854775808"; ERROR: value "9223372036854775808" is out of range for type bigint LINE 1: SELECT '9223372036854775808'::VARINT64::INT8 AS "ERROR: 92... ^ SELECT '-9223372036854775809'::INT8::VARINT64 AS "ERROR: -9223372036854775809"; ERROR: value "-9223372036854775809" is out of range for type bigint LINE 1: SELECT '-9223372036854775809'::INT8::VARINT64 AS "ERROR: -9... ^ SELECT '-9223372036854775809'::VARINT64::INT8 AS "ERROR: -9223372036854775809"; ERROR: value "-9223372036854775809" is out of range for type bigint LINE 1: SELECT '-9223372036854775809'::VARINT64::INT8 AS "ERROR: -9... ^ -- Implicit type conversion tests for varint64 SELECT 1::INT2 + 1::VARINT64 AS "2"; 2 --- 2 (1 row) SELECT 2::INT2 + 2::VARINT64 AS "4"; 4 --- 4 (1 row) SELECT 3::INT2 + 3::VARINT64 AS "6"; 6 --- 6 (1 row) -- Durable type comparison tests for varint64 CREATE TABLE varint64_table(lhs VARINT64, rhs VARINT64); -- Leading/trailing spaces using two or more spaces or tabs INSERT INTO varint64_table VALUES(' 127 ',' 256'); INSERT INTO varint64_table VALUES('128 ',' 4096'); INSERT INTO varint64_table VALUES('4096 ',' -4096 '); INSERT INTO varint64_table VALUES('4567890123456789','4567890123456789'); INSERT INTO varint64_table VALUES('+4567890123456789','-4567890123456789'); INSERT INTO varint64_table VALUES('-1', '0'); INSERT INTO varint64_table VALUES('-1', '-1'); INSERT INTO varint64_table VALUES('-1', '1'); INSERT INTO varint64_table VALUES('-1', '63'); INSERT INTO varint64_table VALUES('-1', '-64'); INSERT INTO varint64_table VALUES('-1', '64'); INSERT INTO varint64_table VALUES('-1', '-65'); INSERT INTO varint64_table VALUES('-1', '8191'); INSERT INTO varint64_table VALUES('-1', '-8192'); INSERT INTO varint64_table VALUES('-1', '8192'); INSERT INTO varint64_table VALUES('-1', '-8193'); INSERT INTO varint64_table VALUES('-1', '1048575'); INSERT INTO varint64_table VALUES('-1', '-1048576'); INSERT INTO varint64_table VALUES('-1', '1048576'); INSERT INTO varint64_table VALUES('-1', '-1048577'); INSERT INTO varint64_table VALUES('-1', '134217727'); INSERT INTO varint64_table VALUES('-1', '-134217728'); INSERT INTO varint64_table VALUES('-1', '134217728'); INSERT INTO varint64_table VALUES('-1', '-134217729'); INSERT INTO varint64_table VALUES('-1', '17179869183'); INSERT INTO varint64_table VALUES('-1', '-17179869184'); INSERT INTO varint64_table VALUES('-1', '17179869184'); INSERT INTO varint64_table VALUES('-1', '-17179869185'); INSERT INTO varint64_table VALUES('-1', '2199023255551'); INSERT INTO varint64_table VALUES('-1', '-2199023255552'); INSERT INTO varint64_table VALUES('-1', '2199023255552'); INSERT INTO varint64_table VALUES('-1', '-2199023255553'); INSERT INTO varint64_table VALUES('-1', '281474976710655'); INSERT INTO varint64_table VALUES('-1', '-281474976710656'); INSERT INTO varint64_table VALUES('-1', '281474976710656'); INSERT INTO varint64_table VALUES('-1', '-281474976710657'); INSERT INTO varint64_table VALUES('-1', '36028797018963967'); INSERT INTO varint64_table VALUES('-1', '-36028797018963968'); INSERT INTO varint64_table VALUES('-1', '36028797018963968'); INSERT INTO varint64_table VALUES('-1', '-36028797018963969'); INSERT INTO varint64_table VALUES('-1', '4611686018427387903'); INSERT INTO varint64_table VALUES('-1','-4611686018427387904'); INSERT INTO varint64_table VALUES('-1', '4611686018427387904'); INSERT INTO varint64_table VALUES('-1','-4611686018427387905'); -- Test bogus inputs INSERT INTO varint64_table (lhs) VALUES (' '); ERROR: invalid input syntax for integer: " " LINE 1: INSERT INTO varint64_table (lhs) VALUES (' '); ^ INSERT INTO varint64_table (lhs) VALUES ('xxx'); ERROR: invalid input syntax for integer: "xxx" LINE 1: INSERT INTO varint64_table (lhs) VALUES ('xxx'); ^ INSERT INTO varint64_table (lhs) VALUES ('3908203590239580293850293850329485'); ERROR: value "3908203590239580293850293850329485" is out of range for type bigint LINE 1: INSERT INTO varint64_table (lhs) VALUES ('390820359023958029... ^ INSERT INTO varint64_table (lhs) VALUES ('-1204982019841029840928340329840934'); ERROR: value "-1204982019841029840928340329840934" is out of range for type bigint LINE 1: INSERT INTO varint64_table (lhs) VALUES ('-12049820198410298... ^ INSERT INTO varint64_table (lhs) VALUES ('- 123'); ERROR: invalid input syntax for integer: "- 123" LINE 1: INSERT INTO varint64_table (lhs) VALUES ('- 123'); ^ INSERT INTO varint64_table (lhs) VALUES (' 123 456 '); ERROR: invalid input syntax for integer: " 123 456 " LINE 1: INSERT INTO varint64_table (lhs) VALUES (' 123 456 '); ^ INSERT INTO varint64_table (lhs) VALUES (''); ERROR: invalid input syntax for integer: "" LINE 1: INSERT INTO varint64_table (lhs) VALUES (''); ^ -- Test table IO SELECT * FROM varint64_table; lhs | rhs ------------------+---------------------- 127 | 256 128 | 4096 4096 | -4096 4567890123456789 | 4567890123456789 4567890123456789 | -4567890123456789 -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | 8191 -1 | -8192 -1 | 8192 -1 | -8193 -1 | 1048575 -1 | -1048576 -1 | 1048576 -1 | -1048577 -1 | 134217727 -1 | -134217728 -1 | 134217728 -1 | -134217729 -1 | 17179869183 -1 | -17179869184 -1 | 17179869184 -1 | -17179869185 -1 | 2199023255551 -1 | -2199023255552 -1 | 2199023255552 -1 | -2199023255553 -1 | 281474976710655 -1 | -281474976710656 -1 | 281474976710656 -1 | -281474976710657 -1 | 36028797018963967 -1 | -36028797018963968 -1 | 36028797018963968 -1 | -36028797018963969 -1 | 4611686018427387903 -1 | -4611686018427387904 -1 | 4611686018427387904 -1 | -4611686018427387905 (44 rows) SELECT * FROM varint64_table WHERE rhs = '4567890123456789'::VARINT64; lhs | rhs ------------------+------------------ 4567890123456789 | 4567890123456789 (1 row) SELECT * FROM varint64_table WHERE rhs <> '4567890123456789'::VARINT64; lhs | rhs ------------------+---------------------- 127 | 256 128 | 4096 4096 | -4096 4567890123456789 | -4567890123456789 -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | 8191 -1 | -8192 -1 | 8192 -1 | -8193 -1 | 1048575 -1 | -1048576 -1 | 1048576 -1 | -1048577 -1 | 134217727 -1 | -134217728 -1 | 134217728 -1 | -134217729 -1 | 17179869183 -1 | -17179869184 -1 | 17179869184 -1 | -17179869185 -1 | 2199023255551 -1 | -2199023255552 -1 | 2199023255552 -1 | -2199023255553 -1 | 281474976710655 -1 | -281474976710656 -1 | 281474976710656 -1 | -281474976710657 -1 | 36028797018963967 -1 | -36028797018963968 -1 | 36028797018963968 -1 | -36028797018963969 -1 | 4611686018427387903 -1 | -4611686018427387904 -1 | 4611686018427387904 -1 | -4611686018427387905 (43 rows) SELECT * FROM varint64_table WHERE rhs < '4567890123456789'::VARINT64; lhs | rhs ------------------+---------------------- 127 | 256 128 | 4096 4096 | -4096 4567890123456789 | -4567890123456789 -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | 8191 -1 | -8192 -1 | 8192 -1 | -8193 -1 | 1048575 -1 | -1048576 -1 | 1048576 -1 | -1048577 -1 | 134217727 -1 | -134217728 -1 | 134217728 -1 | -134217729 -1 | 17179869183 -1 | -17179869184 -1 | 17179869184 -1 | -17179869185 -1 | 2199023255551 -1 | -2199023255552 -1 | 2199023255552 -1 | -2199023255553 -1 | 281474976710655 -1 | -281474976710656 -1 | 281474976710656 -1 | -281474976710657 -1 | -36028797018963968 -1 | -36028797018963969 -1 | -4611686018427387904 -1 | -4611686018427387905 (39 rows) SELECT * FROM varint64_table WHERE rhs > '4567890123456789'::VARINT64; lhs | rhs -----+--------------------- -1 | 36028797018963967 -1 | 36028797018963968 -1 | 4611686018427387903 -1 | 4611686018427387904 (4 rows) SELECT * FROM varint64_table WHERE rhs <= '4567890123456789'::VARINT64; lhs | rhs ------------------+---------------------- 127 | 256 128 | 4096 4096 | -4096 4567890123456789 | 4567890123456789 4567890123456789 | -4567890123456789 -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | 8191 -1 | -8192 -1 | 8192 -1 | -8193 -1 | 1048575 -1 | -1048576 -1 | 1048576 -1 | -1048577 -1 | 134217727 -1 | -134217728 -1 | 134217728 -1 | -134217729 -1 | 17179869183 -1 | -17179869184 -1 | 17179869184 -1 | -17179869185 -1 | 2199023255551 -1 | -2199023255552 -1 | 2199023255552 -1 | -2199023255553 -1 | 281474976710655 -1 | -281474976710656 -1 | 281474976710656 -1 | -281474976710657 -1 | -36028797018963968 -1 | -36028797018963969 -1 | -4611686018427387904 -1 | -4611686018427387905 (40 rows) SELECT * FROM varint64_table WHERE rhs >= '4567890123456789'::VARINT64; lhs | rhs ------------------+--------------------- 4567890123456789 | 4567890123456789 -1 | 36028797018963967 -1 | 36028797018963968 -1 | 4611686018427387903 -1 | 4611686018427387904 (5 rows) SELECT * FROM varint64_table WHERE rhs <> '456'::VARINT64; lhs | rhs ------------------+---------------------- 127 | 256 128 | 4096 4096 | -4096 4567890123456789 | 4567890123456789 4567890123456789 | -4567890123456789 -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | 8191 -1 | -8192 -1 | 8192 -1 | -8193 -1 | 1048575 -1 | -1048576 -1 | 1048576 -1 | -1048577 -1 | 134217727 -1 | -134217728 -1 | 134217728 -1 | -134217729 -1 | 17179869183 -1 | -17179869184 -1 | 17179869184 -1 | -17179869185 -1 | 2199023255551 -1 | -2199023255552 -1 | 2199023255552 -1 | -2199023255553 -1 | 281474976710655 -1 | -281474976710656 -1 | 281474976710656 -1 | -281474976710657 -1 | 36028797018963967 -1 | -36028797018963968 -1 | 36028797018963968 -1 | -36028797018963969 -1 | 4611686018427387903 -1 | -4611686018427387904 -1 | 4611686018427387904 -1 | -4611686018427387905 (44 rows) SELECT * FROM varint64_table WHERE rhs < '456'::VARINT64; lhs | rhs ------------------+---------------------- 127 | 256 4096 | -4096 4567890123456789 | -4567890123456789 -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | -8192 -1 | -8193 -1 | -1048576 -1 | -1048577 -1 | -134217728 -1 | -134217729 -1 | -17179869184 -1 | -17179869185 -1 | -2199023255552 -1 | -2199023255553 -1 | -281474976710656 -1 | -281474976710657 -1 | -36028797018963968 -1 | -36028797018963969 -1 | -4611686018427387904 -1 | -4611686018427387905 (26 rows) SELECT * FROM varint64_table WHERE rhs > '456'::VARINT64; lhs | rhs ------------------+--------------------- 128 | 4096 4567890123456789 | 4567890123456789 -1 | 8191 -1 | 8192 -1 | 1048575 -1 | 1048576 -1 | 134217727 -1 | 134217728 -1 | 17179869183 -1 | 17179869184 -1 | 2199023255551 -1 | 2199023255552 -1 | 281474976710655 -1 | 281474976710656 -1 | 36028797018963967 -1 | 36028797018963968 -1 | 4611686018427387903 -1 | 4611686018427387904 (18 rows) SELECT * FROM varint64_table WHERE rhs <= '456'::VARINT64; lhs | rhs ------------------+---------------------- 127 | 256 4096 | -4096 4567890123456789 | -4567890123456789 -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | -8192 -1 | -8193 -1 | -1048576 -1 | -1048577 -1 | -134217728 -1 | -134217729 -1 | -17179869184 -1 | -17179869185 -1 | -2199023255552 -1 | -2199023255553 -1 | -281474976710656 -1 | -281474976710657 -1 | -36028797018963968 -1 | -36028797018963969 -1 | -4611686018427387904 -1 | -4611686018427387905 (26 rows) SELECT * FROM varint64_table WHERE rhs >= '456'::VARINT64; lhs | rhs ------------------+--------------------- 128 | 4096 4567890123456789 | 4567890123456789 -1 | 8191 -1 | 8192 -1 | 1048575 -1 | 1048576 -1 | 134217727 -1 | 134217728 -1 | 17179869183 -1 | 17179869184 -1 | 2199023255551 -1 | 2199023255552 -1 | 281474976710655 -1 | 281474976710656 -1 | 36028797018963967 -1 | 36028797018963968 -1 | 4611686018427387903 -1 | 4611686018427387904 (18 rows) SELECT * FROM varint64_table WHERE '123'::VARINT64 = lhs; lhs | rhs -----+----- (0 rows) SELECT * FROM varint64_table WHERE '123'::VARINT64 <> lhs; lhs | rhs ------------------+---------------------- 127 | 256 128 | 4096 4096 | -4096 4567890123456789 | 4567890123456789 4567890123456789 | -4567890123456789 -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | 8191 -1 | -8192 -1 | 8192 -1 | -8193 -1 | 1048575 -1 | -1048576 -1 | 1048576 -1 | -1048577 -1 | 134217727 -1 | -134217728 -1 | 134217728 -1 | -134217729 -1 | 17179869183 -1 | -17179869184 -1 | 17179869184 -1 | -17179869185 -1 | 2199023255551 -1 | -2199023255552 -1 | 2199023255552 -1 | -2199023255553 -1 | 281474976710655 -1 | -281474976710656 -1 | 281474976710656 -1 | -281474976710657 -1 | 36028797018963967 -1 | -36028797018963968 -1 | 36028797018963968 -1 | -36028797018963969 -1 | 4611686018427387903 -1 | -4611686018427387904 -1 | 4611686018427387904 -1 | -4611686018427387905 (44 rows) SELECT * FROM varint64_table WHERE '123'::VARINT64 < lhs; lhs | rhs ------------------+------------------- 127 | 256 128 | 4096 4096 | -4096 4567890123456789 | 4567890123456789 4567890123456789 | -4567890123456789 (5 rows) SELECT * FROM varint64_table WHERE '123'::VARINT64 > lhs; lhs | rhs -----+---------------------- -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | 8191 -1 | -8192 -1 | 8192 -1 | -8193 -1 | 1048575 -1 | -1048576 -1 | 1048576 -1 | -1048577 -1 | 134217727 -1 | -134217728 -1 | 134217728 -1 | -134217729 -1 | 17179869183 -1 | -17179869184 -1 | 17179869184 -1 | -17179869185 -1 | 2199023255551 -1 | -2199023255552 -1 | 2199023255552 -1 | -2199023255553 -1 | 281474976710655 -1 | -281474976710656 -1 | 281474976710656 -1 | -281474976710657 -1 | 36028797018963967 -1 | -36028797018963968 -1 | 36028797018963968 -1 | -36028797018963969 -1 | 4611686018427387903 -1 | -4611686018427387904 -1 | 4611686018427387904 -1 | -4611686018427387905 (39 rows) SELECT * FROM varint64_table WHERE '123'::VARINT64 <= lhs; lhs | rhs ------------------+------------------- 127 | 256 128 | 4096 4096 | -4096 4567890123456789 | 4567890123456789 4567890123456789 | -4567890123456789 (5 rows) SELECT * FROM varint64_table WHERE '123'::VARINT64 >= lhs; lhs | rhs -----+---------------------- -1 | 0 -1 | -1 -1 | 1 -1 | 63 -1 | -64 -1 | 64 -1 | -65 -1 | 8191 -1 | -8192 -1 | 8192 -1 | -8193 -1 | 1048575 -1 | -1048576 -1 | 1048576 -1 | -1048577 -1 | 134217727 -1 | -134217728 -1 | 134217728 -1 | -134217729 -1 | 17179869183 -1 | -17179869184 -1 | 17179869184 -1 | -17179869185 -1 | 2199023255551 -1 | -2199023255552 -1 | 2199023255552 -1 | -2199023255553 -1 | 281474976710655 -1 | -281474976710656 -1 | 281474976710656 -1 | -281474976710657 -1 | 36028797018963967 -1 | -36028797018963968 -1 | 36028797018963968 -1 | -36028797018963969 -1 | 4611686018427387903 -1 | -4611686018427387904 -1 | 4611686018427387904 -1 | -4611686018427387905 (39 rows) -- And now for the punchline: test the encoded sizes of various bits SELECT rhs, pg_column_size(rhs) FROM varint64_table WHERE lhs = '-1' ORDER BY rhs ASC; rhs | pg_column_size ----------------------+---------------- -4611686018427387905 | 11 -4611686018427387904 | 10 -36028797018963969 | 10 -36028797018963968 | 9 -281474976710657 | 9 -281474976710656 | 8 -2199023255553 | 8 -2199023255552 | 7 -17179869185 | 7 -17179869184 | 6 -134217729 | 6 -134217728 | 5 -1048577 | 5 -1048576 | 4 -8193 | 4 -8192 | 3 -65 | 3 -64 | 2 -1 | 2 0 | 2 1 | 2 63 | 2 64 | 3 8191 | 3 8192 | 4 1048575 | 4 1048576 | 5 134217727 | 5 134217728 | 6 17179869183 | 6 17179869184 | 7 2199023255551 | 7 2199023255552 | 8 281474976710655 | 8 281474976710656 | 9 36028797018963967 | 9 36028797018963968 | 10 4611686018427387903 | 10 4611686018427387904 | 11 (39 rows) -- Cleanup DROP TABLE varint64_table; DROP EXTENSION varint CASCADE;