title: nodejs + postgresql - syntax error at or near "s" - scanner_yyerror
body: <p>I'm trying to store texts into a table, like this:</p>
  
  <pre><code>let insert_query = "insert into Messages(mid, mdate, sender, mtype, reply_to, is_forwarded, mtext, size, resolution, duration, emoji)"
  insert_query += `values ('${message_id}', to_timestamp('${message_date}', 'DD.MM.YYYY HH24:MI:SS'), '${from_name}', '${media_type}', '${reply_to}', ${is_forwarded}, '${text}', '${media_size}', '${photo_resolution}', '${media_duration}', '${sticker_emoji}');`
  </code></pre>
  
  <p>This is a rather long query, the important part to notice is where I add <code>'${text}'</code> into the <code>mtext</code> field.</p>
  
  <p>I received this error:</p>
  
  <pre><code>{ error: syntax error at or near "s"
      at Connection.parseE (/home/amirashabani/Amir/Code/telyzer/node_modules/pg/lib/connection.js:602:11)
      at Connection.parseMessage (/home/amirashabani/Amir/Code/telyzer/node_modules/pg/lib/connection.js:399:19)
      at Socket.&lt;anonymous&gt; (/home/amirashabani/Amir/Code/telyzer/node_modules/pg/lib/connection.js:121:22)
      at Socket.emit (events.js:198:13)
      at addChunk (_stream_readable.js:288:12)
      at readableAddChunk (_stream_readable.js:269:11)
      at Socket.Readable.push (_stream_readable.js:224:10)
      at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
    name: 'error',
    length: 91,
    severity: 'ERROR',
    code: '42601',
    detail: undefined,
    hint: undefined,
    position: '251',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'scan.l',
    line: '1134',
    routine: 'scanner_yyerror' }
  </code></pre>
  
  <p>I printed the <code>insert_query</code> for when these errors happen, and here are some of the results:</p>
  
  <pre><code>insert into Messages(mid, mdate, sender, mtype, reply_to, is_forwarded, mtext, size, resolution, duration, emoji)
  values ('message8224', to_timestamp('21.06.2019 21:27:34', 'DD.MM.YYYY HH24:MI:SS'), 'AmirAShabani', 'text', '', false, 'he's a loser', '', '', '', '');
  </code></pre>
  
  <p>I can see that the problem is with the single quote character. I tried to replace it with <code>\'</code>, like this: </p>
  
  <pre><code>text = child['children'][0]['data'].trim().replace('\'', '\\\'')
  </code></pre>
  
  <p>But that doesn't help either, and I'm not quite sure I should do that to begin with.</p>
  
  <p>How can I fix it?</p>