5 ms·
I'm really confused by this post. Wouldn't it be simpler to read a few bytes from /dev/random? Sure, it wouldn't be portable to windows but that's more of a fe
by literalAardvark 2y ago
I'm really confused by this post. Wouldn't it be simpler to read a few bytes from /dev/random?
Sure, it wouldn't be portable to windows but that's more of a feature than a bug.
- freeqaz 2y agoHow do you read from a file like that in SQL? I know that this is in "theory" possible but I've never had a legitimate use case where I've needed to do file I/O from my ORM, lol. This is the ChatGPT answer that I was able to derive: > You can read from `/dev/urandom` in a PostgreSQL query using `plperlu`, which allows executing unsafe Perl code. > Create a function to read random bytes: CREATE EXTENSION plperlu; CREATE OR REPLACE FUNCTION get_random_bytes(num_bytes int) RETURNS bytea LANGUAGE plperlu AS $$ my $num_bytes = $_[0]; open my $urandom, '<', '/dev/urandom' or die "Cannot open /dev/urandom: $!"; read $urandom, my $bytes, $num_bytes; close $urandom; return $bytes; $$; SELECT get_random_bytes(16);
- aaomidi 2y ago/dev/urandom. Some systems have basically made them equivalent though.