title: Presto MD5 Hash for multiple Columns in DB Table
body: <p>I am facing a challenge that's driving me crazy after two hours of trial and error... </p>
  
  <p>I need to hash at least two columns of a relational table with presto (actually with Amazon Athena which uses the presto engine). </p>
  
  <p>My current state is this:</p>
  
  <pre><code>SELECT concat(lower(to_hex(md5(to_utf8(trim(column1))))),
                lower(to_hex(md5(to_utf8(trim(column2)))))) AS HK
  FROM table
  limit 10
  </code></pre>
  
  <p>The issue with this is, it hashes the columns first and afterwards concatenates them what ends up looking like this, because it concatenates the hashes: </p>
  
  <pre><code>8f9bfe9d1345237cb3b2b205864da075ce8ae9da5b7cd6c3df2929543a9af92d
  </code></pre>
  
  <p>Instead of concatenating the strings first and then hashing it what should end up like this:</p>
  
  <pre><code>8f9bfe9d1345237cb3b2b205864da075
  </code></pre>
  
  <p>I'd be very grateful for any ideas on how to solve this problem. </p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I got a solution, but only without using the trim() function, with it the query does not work and results in an error message </p>
  
  <blockquote>
    <p>INVALID_FUNCTION_ARGUMENT: There must be two or more concatenation arguments</p>
  </blockquote>
  
  <p>Current query: </p>
  
  <pre><code>SELECT lower(to_hex(md5(to_utf8(concat(user, email))))) AS UserMailHK FROM table limit 10
  </code></pre>
  
  <p>Any ideas on this? </p>