I apologize if this has been answered elsewhere. I found similar posts but nothing that exactly matches what I was looking for. I am wondering if it is possible to randomly assign a number as data is entered into a table. For example, for this table
CREATE TABLE test (
id_number INTEGER NOT NULL,
second_number INTEGER NOT NULL)
I would like to be able to do the following:
INSERT INTO test (second_number)
VALUES (1234567)
where id_number is then populated with a random 10-digit number. I guess I want this similar to SERIAL in the way it populates but it needs to be 10 digits and random. Thanks very much
You can try this expression:
CAST(1000000000 + floor(random() * 9000000000) AS bigint)
This will give you a random number between 1000000000 and 9999999999.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With