title: Postgresql query problems for nodejs
body: <p>I am making an app with <strong>node.js</strong>, using the <strong>express</strong> framwork, woth <strong>postgresql</strong> as my database.</p>
  
  <p>I have to insert some values into my database, and some of them have quotes. e.g. <strong>Tony's Seafood Restaurant</strong>. I cannot insert values like this.</p>
  
  <p>I tried</p>
  
  <pre><code>name.replace('\'', '\\\'');
  </code></pre>
  
  <p>and also</p>
  
  <pre><code>name.replace("'", "\'");
  </code></pre>
  
  <p>but no success.</p>
  
  <p>Problem is the postgresql server formats queries before running them. If the query look like this in my code,</p>
  
  <pre><code>insert into venues values (nextval('venue_venueid_seq'),'"+name+"','"+api+"','"+location+"','"+latitude+"','"+longitude+"','"+category+"','"+category_generalized+"')
  </code></pre>
  
  <p>then postgresql formats it like this (i found it by printing the client.query object)</p>
  
  <pre><code>insert into venues values (nextval(\'venue_venueid_seq\'),\'Tony\'s Seafood Restaurant\',\'Google Places\',\'18863 California 1, Marshall\',\'38.146777\',\'-122.882987\',\'restaurant,food,establishment\',\'Eatery,Eatery,establishment\')
  </code></pre>
  
  <p>You see postgresql already places slashes before the starting and the ending quotes of my string, so the escape slashes I programatically inserted in the middle of the string are not working.</p>
  
  <p>How can I insert values like this? Please help.</p>