title: Parameterized query in Postgresql with a json array
body: <p>I would like to invoke array_prepend into a json[] using a parameterized query. I am using pg-promise npm package but this uses the normal node-postgres adapter under the hood.</p>
  
  <p>My query is:</p>
  
  <pre><code>db.query(`update ${schema}.chats set messages =
    array_prepend('{"sender":"${sender}","tstamp":${lib.ustamp()},"body":$1}',messages) where chat_id = ${chat_id}`
   , message));
  </code></pre>
  
  <p>Same with "$1".</p>
  
  <p>It works with a non-parameterized query. </p>
  
  <p>Above code produces :</p>
  
  <blockquote>
    <p>{ [error: syntax error at or near "hiya"]</p>
  </blockquote>
  
  <p>Main reason for this is to avoid sql injection (docs say that they escape adequately when using the parameterized queries). </p>