admin管理员组文章数量:1394402
For testing purposes on a table like this:
CREATE TABLE my_table (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
.
.
...I would like to get the same id
's on each test run to better compare test logs / test results.
Do there exist a function that works for gen_random_uuid()
the same way setseed(x)
works for random()
?
gen_random_uuid()
returns version 4 UUIDs that does not include timestamps so I can't see why this shouldn't be possible. I guess I could always write my own my_gen_random_uuid()
based on random()
with some hex string trickery, but that would be much slower.
Example - the dice column always return the same values when running these two selects, the uuid column always varies but I don't want it to:
select setseed(1/7.0);
select floor(1+random()*6) dice, gen_random_uuid() from generate_series(1,7) order by 1,2;
dice | gen_random_uuid
------+--------------------------------------
2 | 27539fb8-da6d-4976-945e-1a84948b6d1f
3 | 3969c800-70a2-48d0-b3e4-13edf02ee7fa
3 | b68949b5-67b2-4786-b1f4-23654439e037
3 | df1061d1-e890-4222-a4ea-d42c90d15435
4 | ef1ce38e-1199-4101-9e40-a0eb930c492b
5 | 81fe87fa-eab5-4229-b591-d83ae528353b
6 | 54c61441-70e5-4d83-a08e-7b3662d20970
(7 rows)
本文标签: postgresqlHow to set a seed for genrandomuuid()Stack Overflow
版权声明:本文标题:postgresql - How to set a seed for gen_random_uuid()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744088337a2588953.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论