© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
3 replies
Deleted User

Creating a random_username function with SQL Editor

Hey there, sorry this might be a little basic of a question but I'm really new to Postgres and need some help.

I'm in the process of creating a new random_username function that will return a username formatted like so:
user1234567890
user1234567890
.

As far as creating this function I'm creating a new SQL snippet that I have structured as so:

create or replace function random_username()
returns username as $$
  declare
    
  begin
    
  end;
$$ language plpgsql security definer;
create or replace function random_username()
returns username as $$
  declare
    
  begin
    
  end;
$$ language plpgsql security definer;


From here, I can't find much on how to future construct this function. Some docs I'm using are as follows:

https://www.techonthenet.com/postgresql/functions/random.php

I think the random() function would be perfect for this. How can I concat "user" + random numbers together in my function?

Again, I apologize this is probably super basic. I'm just so new to this that it looks harder than it seems.
PostgreSQL: random Function
This PostgreSQL tutorial explains how to use the PostgreSQL random function with syntax and examples. The PostgreSQL random function can be used to return a random number or a random number within a range.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

SQL Editor
SupabaseSSupabase / help-and-questions
7mo ago
Invoking a local edge function from local SQL editor
SupabaseSSupabase / help-and-questions
4y ago
Get results of created function in SQL editor with select.
SupabaseSSupabase / help-and-questions
4y ago
Help with SQL function
SupabaseSSupabase / help-and-questions
4y ago