On Sat, Dec 23, 2023 at 8:36 AM Phillip Diffley wrote:
>
> Thank you for all the suggestions! I ended up using pgcrypto's
> pg_random_bytes() to build the random int. I haven't fully tested the
> function yet, but it looks like this works.
>
> CREATE EXTENSION IF NOT EXISTS pgcrypto;
> CREATE OR R
Thank you for all the suggestions! I ended up using pgcrypto's
pg_random_bytes() to build the random int. I haven't fully tested the
function yet, but it looks like this works.
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE OR REPLACE FUNCTION gen_random_int() RETURNS INT8 AS $$
DECLARE
bytes byt
On 2023-12-21 00:06:39 -0600, Phillip Diffley wrote:
> 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
> Post
On Thu, Dec 21, 2023 at 7:21 PM Tom Lane wrote:
> Phillip Diffley 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
> > g
Phillip Diffley 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 the
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?
Thanks,
Phillip