Here is what i have tried so far but some times its returning 3 digit or 2 digit or even 1 digit number.
SELECT num
FROM GENERATE_SERIES (1, 10000) AS s(num)
order by random()
LIMIT 1
Here is what i have tried so far but some times its returning 3 digit or 2 digit or even 1 digit number.
SELECT num
FROM GENERATE_SERIES (1, 10000) AS s(num)
order by random()
LIMIT 1
You can use this expression to avoid dealing with sub-queries
select floor(1000 + random() * 8999);
You generate all numbers between 1 and 10000, so 1-999 and 10000 are not 4 digit numbers but in the list:
SELECT num
FROM GENERATE_SERIES (1000, 9999) AS s(num) // generates 4 digit numbers
order by random()
LIMIT 1
You can try below
SELECT num
FROM GENERATE_SERIES (1000, 9999) AS s(num)
order by random()
LIMIT 1
It will generate value from 1 to 10000
select to_char(n, 'FM0000') FROM floor(random()*10000) as x(n);