title: Aggregate hash function?
body: <p>Just like we have aggregate functions of sum and count, is there any way to do aggregate hashes on field?  For example, assume you have the following recordset:</p>
  
  <pre><code>Name     ID
  Bob      1
  Bob      2
  Bob      3
  Bob      4
  </code></pre>
  
  <p><em>Conceptually</em>, I'd like to do this:</p>
  
  <pre><code>select name, hash(id) from mydb.mytable
  group by 1
  </code></pre>
  
  <p>...which would return this:</p>
  
  <pre><code>Name     ID
  Bob      D8-F0-00-91
  </code></pre>
  
  <p>If I delete the record with ID = 3, the aggregate would then return this:</p>
  
  <pre><code>Name     ID
  Bob      A8-EB-6D-1D
  </code></pre>
  
  <p>FYI, I used <code>select hashrow(1,2,3,4)</code> and <code>select hashrow(1,2,4)</code> to get the above hash values.</p>
  
  <p><strong>Update for dnoeth:</strong>  It's probably helpful to mention that I need the resulting aggregate to be unique.  Here's an example of the data model I am using:</p>
  
  <pre><code>table office (Id integer)
  table employee (Id integer, OfficeId integer)
  </code></pre>
  
  <p>Each office has employees, so it's a one-to-many from office to employee with the employee table having OfficeId as a FK to the office table.</p>
  
  <pre><code>locking row for access
  select n, count(n) from
  (
      select 
          officeid, 
          sum(cast(from_bytes('00'xb || hashrow(id), 'base10') as bigint)) n 
      from mydb.employee
      group by 1
  ) x
  group by 1
  </code></pre>
  
  <p>Here's a great example of how a collision occurs.  Again, though, I didn't mention that I needed the result to be unique.</p>
  
  <pre><code>select 
      cast(from_bytes('00'xb || hashrow(2300015), 'base10') as bigint) +
      cast(from_bytes('00'xb || hashrow(14100028), 'base10') as bigint) hash1,
  
      cast(from_bytes('00'xb || hashrow(1000004), 'base10') as bigint) +
      cast(from_bytes('00'xb || hashrow(3100014), 'base10') as bigint) +
      cast(from_bytes('00'xb || hashrow(12300025), 'base10') as bigint) hash2
  </code></pre>