git.postgresql.org Git - postgresql.git/commit

git projects / postgresql.git / commit
? search:
summary | shortlog | log | commit | commitdiff | tree
(parent: 818861e) | patch
Add functions to generate random numbers in a specified range.
2024年3月27日 10:12:39 +0000 (10:12 +0000)
2024年3月27日 10:12:39 +0000 (10:12 +0000)
commit e6341323a8da64b18e9af3e75a4578230702d61c
Add functions to generate random numbers in a specified range.

This adds 3 new variants of the random() function:

random(min integer, max integer) returns integer
random(min bigint, max bigint) returns bigint
random(min numeric, max numeric) returns numeric

Each returns a random number x in the range min <= x <= max.

For the numeric function, the number of digits after the decimal point
is equal to the number of digits that "min" or "max" has after the
decimal point, whichever has more.

The main entry points for these functions are in a new C source file.
The existing random(), random_normal(), and setseed() functions are
moved there too, so that they can all share the same PRNG state, which
is kept private to that file.

Dean Rasheed, reviewed by Jian He, David Zhang, Aleksander Alekseev,
and Tomas Vondra.

Discussion: https://postgr.es/m/CAEZATCV89Vxuq93xQdmc0t-0Y2zeeNQTdsjbmV7dyFBPykbV4Q@mail.gmail.com
13 files changed:
doc/src/sgml/func.sgml diff | blob | blame | history
src/backend/utils/adt/Makefile diff | blob | blame | history
src/backend/utils/adt/float.c diff | blob | blame | history
src/backend/utils/adt/meson.build diff | blob | blame | history
src/backend/utils/adt/numeric.c diff | blob | blame | history
src/backend/utils/adt/pseudorandomfuncs.c [new file with mode: 0644] blob
src/common/pg_prng.c diff | blob | blame | history
src/include/catalog/catversion.h diff | blob | blame | history
src/include/catalog/pg_proc.dat diff | blob | blame | history
src/include/common/pg_prng.h diff | blob | blame | history
src/include/utils/numeric.h diff | blob | blame | history
src/test/regress/expected/random.out diff | blob | blame | history
src/test/regress/sql/random.sql diff | blob | blame | history
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /