title: How can I generate a unique string per record in a table in Postgres?
body: <p>Say I have a table like posts, which has typical columns like id, body, created_at. I'd like to generate a unique string with the creation of each post, for use in something like a url shortener. So maybe a 10-character alphanumeric string. It needs to be unique within the table, just like a primary key.</p>
  
  <p>Ideally there would be a way for Postgres to handle both of these concerns:</p>
  
  <ol>
  <li>generate the string</li>
  <li>ensure its uniqueness</li>
  </ol>
  
  <p>And they must go hand-in-hand, because my goal is to not have to worry about any uniqueness-enforcing code in my application.</p>