title: Hasql: Error from variable substitution in 'SET' statement
body: <p>I'm trying to write a parameterized statement with Hasql to set a variable in PostgreSQL.</p>
  
  <pre><code>import qualified Hasql.Encoders as E
  import qualified Hasql.Decoders as D
  
  setOrganization :: Query Int64 ()
  setOrganization = statement sql (E.value E.int8) D.unit False
    where
      sql = "set my_session.organization_id = $1"
  </code></pre>
  
  <p>The result from the above is:</p>
  
  <pre><code>ResultError (ServerError "42601" "syntax error at or near \"$1\"" Nothing Nothing)
  </code></pre>
  
  <p>Adding single quotes e.g.</p>
  
  <pre><code>    sql = "set my_session.organization_id = '$1'"
  </code></pre>
  
  <p>Gives this result when I run a query using the variable:</p>
  
  <pre><code>ResultError (ServerError "22P02" "invalid input syntax for integer: \"$1\"" Nothing Nothing)
  </code></pre>
  
  <p>Which does make sense since the <code>organization_id</code> is a <code>bigint</code> / <code>int8</code>.</p>
  
  <p>Hard-coding the <code>$1</code> value in either format works. I've tried different Hasql types e.g. <code>E.text</code> and <code>E.unknown</code> and that does not work.</p>
  
  <hr>
  
  <p>Update: Using the more primitive <code>execParams</code> function from <code>postgresql-libpq</code>.</p>
  
  <pre><code>execParams c "SET my_session.organization_id = '$1'" [Just (Oid 20, "1",Text)] Text
  </code></pre>
  
  <p>Unquoted variable gives <code>FatalError</code> result. Single-quoted variable gives <code>CommandOk</code>, but is wrong type  (not <code>bigint</code>) for later queries.</p>