Questions tagged [random]
71 questions
22
votes
3 answers
How can I generate a random bytea
I would like to be able to generate random bytea fields of arbitrary length (<1Gb) for populating test data.
What is the best way of doing this?
Jack Douglas
- 37,076
- 14
- 93
- 173
16
votes
3 answers
Create hierarchy of multiple levels where each node has a random number of children
I need to create some test data that involves a hierarchy. I could make it easy and do a couple of CROSS JOINs, but that would give me a structure that is completely uniform / without any variation. That not only seems dull, but lack of variation in…
Solomon Rutzky
- 65,256
- 6
- 135
- 267
15
votes
3 answers
Set random value from set
I need to put some random values into database, but I don't want to end up with completely randomized text (like 7hfg43d3). Instead I would like to randomly pick one of values supplied by myself.
korda
- 575
- 2
- 6
- 11
15
votes
2 answers
How to create column in DB with default value random string
Can I create column in DB table (PostgreSQL) which have default value random string, and how ?
If is not possible, please let me know that.
tasmaniski
- 1,005
- 4
- 11
- 16
8
votes
1 answer
Randomizing the Auto Increment in Mysql
We have a database, where we insert data into table whenever we receive an order from our services.
We use auto_increment to generate the ID and assign the order with the same.
This is usually same everywhere.
But the problem is, since this…
RaceBase
- 193
- 1
- 1
- 7
8
votes
4 answers
How do I do a complex GROUP BY in MySQL?
I have a table that contains several keys into other tables (where each key is comprised of multiple columns). I would like to be able to group rows together that have an equal key, but I don't want to group all of them together. It's not a simple…
Michael McGowan
- 759
- 2
- 10
- 20
7
votes
2 answers
PostgreSQL randomising combinations with LATERAL
In the following example I have a table foo from which I'd like to pick out at random a row per group.
CREATE TABLE foo (
line INT
);
INSERT INTO foo (line)
SELECT generate_series(0, 999, 1);
Let's say that I'd like to group by line % 10. I could…
beldaz
- 1,580
- 3
- 14
- 23
5
votes
2 answers
How to Randomly Select a Date?
I am using in a Bash Shell Script this code for retrieving a random date.
Is there a way to do that also in Microsoft SQL Server?
I can imagine that through a single SELECT query and probably by calling a few functions that can be performed easily,…
user62547
5
votes
5 answers
Get a truly RANDOM row from a PostgreSQL table quickly
I always used to do:
SELECT column FROM table ORDER BY random() LIMIT 1;
For large tables, this was unbearably, impossibly slow, to the point of being useless in practice. That's why I started hunting for more efficient methods. People…
user200642
5
votes
1 answer
How do I make MySQL auto increment in random order?
I have a table that contains several keys into other tables (where each key is comprised of multiple columns). I would like to create a new column for each key that would be an integer such that value i represents the ith occurrence of that key…
Michael McGowan
- 759
- 2
- 10
- 20
5
votes
1 answer
May postgresql's uuid_generate_v1() conflict when we change the computer date/time?
According to postgresql uuid-ossp documentation uuid_generate_v1() is based on Mac address + timestamp:
https://www.postgresql.org/docs/9.4/static/uuid-ossp.html
On a distributed database scenario where we have hundreds of databases generating…
Thiago Sayão
- 385
- 3
- 14
5
votes
1 answer
Generate fake data for several tables with relationships
I have 3 tables where I want to generate fake data in UsersCategoryLink.
How can I insert in the table UserCategoryLink the column UserID with random users from the table User and a random id from the table Categories. In this SQL fiddle you can see…
H. Pauwelyn
- 908
- 4
- 15
- 35
4
votes
2 answers
Sampling in PostgreSQL
I am looking for possible ways of random sampling in PostgreSQL. I found a couple of methods to do that with different advantages and disadvantages. The naive way to do that is:
select * from Table_Name
order by random()
limit 10;
Another faster…
Rana
- 43
- 1
- 4
4
votes
3 answers
Select random 10 unique rows from MySQL database?
I have one table (questions) with 54 questions.
The students have to answer all 54 questions.
I have to show 10 questions at once, then next 10 and so on....
I have to select 10 questions randomly and next 10 random questions except the previous…
Bikram Pahi
- 267
- 2
- 4
- 12
4
votes
2 answers
How did this statement update 3 rows in Postgres?
I am curious how this statement updated 3 rows in Postgres. All the other times I ran it, it would update 0 or 1. Is there a way to find out which rows?
bestsales=# update keyword set revenue = random()*10 where id = cast(random()*99999 as…
Chloe
- 186
- 1
- 8