-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
k/enhancementNew feature or improve an existing featureNew feature or improve an existing feature
Description
Is your proposal related to a problem?
I'd like to create a custom SQL function that generates ids in a format such as pc_1Pa04ELJnaZjX5rdwAEd0YMV. Id like to use this as the default value of a id field (type text). Similar to how gen_uuid() can be used for UUID type fields.
The current guidance found in the docs is not ideal. I don't want to set id to null for data integrity reasons.
Describe the solution you'd like
Here's an example. I'd like to generate ids using this nanoid fn: https://github.com/elitan/postgres-nanoid/blob/main/nanoid.sql
I then create another function that uses nanoid and takes 0 args
CREATE OR REPLACE FUNCTION userid()
RETURNS text
LANGUAGE plpgsql
VOLATILE
PARALLEL SAFE
AS $$
BEGIN
RETURN nanoid('user_', 24);
END
$$;Id then expect userid() to appear in this list of default functions:
Metadata
Metadata
Assignees
Labels
k/enhancementNew feature or improve an existing featureNew feature or improve an existing feature