I need to insert k random numbers (in the range 1:n) concatenated by | into a column of a table 'X', where n is the number of rows in table 'Y', in a PostgreSQL procedure.
To find the number of rows in the table 'Y'
select count(*) into n from Y
This will generate k random numbers in the range 1:n
SELECT num FROM GENERATE_SERIES (1, n) AS s(num) ORDER BY RANDOM() LIMIT k;
How do I concatenate the k integers with | and insert them into 'X'?
Aucun commentaire:
Enregistrer un commentaire