Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created June 2, 2015 01:07
Show Gist options
  • Save jbnv/ca5a7829927a6b8f2308 to your computer and use it in GitHub Desktop.
Save jbnv/ca5a7829927a6b8f2308 to your computer and use it in GitHub Desktop.
Name Generator (PostgreSQL; English)
SELECT
arrays.firstnames[s.a % ARRAY_LENGTH(arrays.firstnames,1) + 1] AS firstname,
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ' from s.a%26+1 for 1) AS middlename,
arrays.lastnames[s.a % ARRAY_LENGTH(arrays.lastnames,1) + 1] AS lastname
FROM generate_series(1,300) AS s(a) -- number of names to generate
CROSS JOIN(
SELECT ARRAY[
'Adam','Bill','Bob','Calvin','Donald','Dwight','Frank','Fred','George','Howard',
'James','John','Jacob','Jack','Martin','Matthew','Max','Michael',
'Paul','Peter','Phil','Roland','Ronald','Samuel','Steve','Theo','Warren','William',
'Abigail','Alice','Allison','Amanda','Anne','Barbara','Betty','Carol','Cleo','Donna',
'Jane','Jennifer','Julie','Martha','Mary','Melissa','Patty','Sarah','Simone','Susan'
] AS firstnames,
ARRAY[
'Matthews','Smith','Jones','Davis','Jacobson','Williams','Donaldson','Maxwell','Peterson','Stevens',
'Franklin','Washington','Jefferson','Adams','Jackson','Johnson','Lincoln','Grant','Fillmore','Harding','Taft',
'Truman','Nixon','Ford','Carter','Reagan','Bush','Clinton','Hancock'
] AS lastnames
) AS arrays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment