title: PostgreSQL password generator
body: <p>I need some help with sql pass generator. I already have a function which returns 8 random characters, but I have to be sure, that there are lowercase and uppercase characters and numbers. Any advice? Here is my old function.</p>
  
  <pre><code>CREATE FUNCTION f_generate_password() RETURNS text AS $$
  DECLARE
     password text;
     chars text;
  BEGIN
     password := '';
     chars := 
  'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
     FOR i IN 1..8 LOOP
       password := password || SUBSTRING(chars, 
  ceil(random()*LENGTH(chars))::integer, 1);
     END LOOP;
     return password;
  END;
  $$
  LANGUAGE plpgsql;
  </code></pre>