As 3manuek mentioned, there are functions and operators to deal with IP addresses - be it IPv4 or IPv6.
I am wondering a bit where your number comes from. The address range you gave translates to
which is an address range of length 1.
If you meant all possible addresses starting with '2001:dd8:', then the correct designation of this range would be
2001:dd8::/32, as it is the first 32 bits that are given. According to a calculator tool, the resulting range is the following:
Start Range: 2001:dd8:0:0:0:0:0:0
End Range: 2001:dd8:ffff:ffff:ffff:ffff:ffff:ffff
No. of host: 79228162514264337593543950336
Meanwhile, if you omit the block size (
/32), you get a single address (the one I showed above).
So, there is a way to get the number provided by the calculator, using builtin PostgreSQL functionality. Our friend here is
SELECT round(2 ^ (128 - masklen('2001:dd8::/32'::cidr))::numeric);
The result is the same as form the calculator. The rounding is there for removing the decimal point and the zeros after it, which are the result of casting to