Company
Date Published
Author
Franck Pachot
Word count
569
Language
English
Hacker News points
None

Summary

The Orafce extension for PostgreSQL provides a function called `dbms_random.string` which can be used to generate random strings of varying lengths, with options to specify different character sets such as printable characters, alphabetical characters, or uppercase letters. The function takes two parameters: the length of the string and the character set to use. For example, `dbms_random.string('P', 42)` would generate a random string of length 42 using only printable characters. The extension is compatible with PostgreSQL-compatible databases like YugabyteDB. However, there are some differences in behavior between Orafce and Oracle's built-in function for generating random strings, including the ability to return certain special characters like `\` and `~`. To work around this issue, a workaround has been implemented by making the function volatile instead of immutable, which is equivalent to making it deterministic in Oracle. Additionally, when creating the extension, the Orafce functions are deployed to schemas with the same name as the Oracle package they emulate. The Orafce extension provides many useful and convenient utility functions that can enhance the PostgreSQL ones.