Search Postgresql Archives

Re: How to generate random bigint

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Phillip Diffley <phillip6402@xxxxxxxxx> writes:
> Postgres's random() function generates a random double. That can be
> converted to a random int for smaller integers, but a double can't
> represent all of the values in a bigint. Is there a recommended way to
> generate a random bigint in Postgres?

Doesn't look like there's anything directly exposed for that.
Since PG v13 you could use gen_random_uuid, if you're careful
to extract only bits that aren't fixed by the v4 UUID spec.
pgcrypto's pg_random_bytes() function offers another
some-assembly-required solution that'd work considerably
further back.  Or you could make a custom C function that
leverages pg_strong_random().

			regards, tom lane





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux