Khan W
08/02/2021, 6:28 PMsql
select your_columns from your_table ORDER BY random()
burggraf
08/02/2021, 6:55 PMburggraf
08/02/2021, 6:55 PMconst { data, error } = await this.supabase
.from('questions')
.select('*')
.order('id', { ascending: true })
.filter('id', 'gte', this.uuid() /* create a random uuid */)
.limit(1);
burggraf
08/02/2021, 6:56 PMburggraf
08/02/2021, 6:56 PMpublic uuid() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (char) => {
let random = Math.random() * 16 | 0;
let value = char === "x" ? random : (random % 4 + 8);
return value.toString(16);
});
}
Khan W
08/02/2021, 7:11 PMburggraf
08/02/2021, 7:30 PMORDER BY random()
with very large recordsets, since it's using an existing index.babayaga
08/03/2021, 2:07 PM