NOTE
rw_int256
values can be very large, and therefore require more memory and processing power compared to smaller data types.
Overview
rw_int256
is a custom data type that represents a signed 256-bit integer with a storage size of 32 bytes.
It is designed to handle large integer values, and can be useful in financial calculations, cryptography, and data analysis.
Usage
You can define a column with the rw_int256
type:
CREATE TABLE table_name (column_name rw_int256);
CREATE TABLE t (v rw_int256);
INSERT INTO t VALUES (1), (100), (10000), (100000000), (10000000000000000), ('100000000000000000000000000000000'), (0), (-1), (-100), (-10000), (-100000000), (-10000000000000000), ('-100000000000000000000000000000000');
Casting
You can also convert other data types to rw_int256
:
cast ('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe' AS rw_int256);
'10000000000000000' :: rw_int256;
Or convert rw_int256
to double
.
Supported functions
count
Returns the number of non-null rows.
count ( [ DISTINCT ] rw_int256 ) -> bigint
min
Returns the minimum value in a set of values.
min ( rw_int256 ) -> rw_int256
-100000000000000000000000000000000
max
Returns the maximum value in a set of values.
max ( rw_int256 ) -> rw_int256
100000000000000000000000000000000
sum
Returns the sum of all input values.
sum ( [ DISTINCT ] rw_int256 ) -> rw_int256
avg
Returns the average (arithmetic mean) of the selected values.
avg ( [ DISTINCT ] rw_int256 ) -> double
hex_to_int256
Converts a hexadecimal string to a 256-bit integer.
hex_to_int256 ( string ) -> rw_int256
SELECT hex_to_int256('0xdeadbeef');
SELECT hex_to_int256('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01');
Standard deviation and variance
Returns population standard deviation, sample standard deviation, population variance, and sample variance.
stddev_pop ( rw_int256 ) -> double -- standard deviation
stddev_samp ( rw_int256 ) -> double -- sample standard deviation
var_pop ( rw_int256 ) -> double -- population variance
var_samp ( rw_int256 ) -> double -- sample variance
SELECT stddev_pop(v), stddev_samp(v), var_pop(v), var_samp(v) FROM t;
stddev_pop | stddev_samp | var_pop | var_samp
------------------------+----------------------+------------------------+------------------------
3.9223227027636808e+31 | 4.08248290463863e+31 | 1.5384615384615386e+63 | 1.6666666666666666e+63
(1 row)