lundi 21 septembre 2020

Generating a random 10-digit ID number in PostgreSQL

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




Aucun commentaire:

Enregistrer un commentaire