PRQL / prql

PRQL is a modern language for transforming data — a simple, powerful, pipelined SQL replacement
https://prql-lang.org
Apache License 2.0
9.58k stars 208 forks source link

Random function #4661

Open vanillajonathan opened 1 week ago

vanillajonathan commented 1 week ago

What's up?

PRQL does not yet have any random function(s). SQL have the RAND function which can be used awkwardly used using s-strings.

It would be nice if PRQL has a random function, it could work like randint in Python, i.e. take in a low and high parameter in order to specify a range. The SQL RAND function does not have this feature it can takes a seed as parameter.

derive { random_value = (random low:100 high:1000) }
SELECT FLOOR(100 + RAND() * (1000 - 100 + 1)) AS random_value;

It could even generate a random letter:

derive { random_letter = (random low:A high:Z) }
SELECT CHAR(FLOOR(RAND() * (ASCII('A') - ASCII('Z')))) AS random_letter;
max-sixty commented 1 week ago

Yes, would be happy to add this. Probably start with math.randint?

@vanillajonathan if you want to add, search for math.abs as an example.

aljazerzen commented 15 hours ago

Note that random is an impure function and suffer from a the problem described in #1111