go-tableland icon indicating copy to clipboard operation
go-tableland copied to clipboard

[GOT-56] feat: add support for randomness in SQL queries

Open dtbuchholz opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe.

Normal SQL supports a randomness function, which can be useful for both read and write queries. I'd like to leverage something similar to the RANDOM() function in Tableland to help increase the parity with native SQL.

Describe the solution you'd like

Create/enable support for a RANDOM([seed]) function that generates a random number. This could be used in a read or write query:

SELECT * FROM mytable ORDER BY random()
INSERT INTO mytable VALUES (random())

Ideally, the RANDOM keyword could be used for 1:1 SQLite parity to reduce potential friction there, but this may not be possible and might require something like RANDOM_TBL(). Non-SQLite SQL often use RAND, in case that's possible.

Describe alternatives you've considered

Using something like ChainLink VRF, which may still be useful but adds a significant cost for "more secure" rng guarantees.

Additional context

Discussion about this in Discord: here. For context, the SQLite random() and randomblob() both use pseudo-rng: here.

GOT-56

dtbuchholz avatar Sep 19 '22 21:09 dtbuchholz