title: Postgres date range insertion using Dapper and Npgsql
body: <p>I'm trying to use Dapper to insert a date range into my Postgres database, using code like this: </p>
  
  <pre><code>string INSERT_DATE_RANGE = @"INSERT INTO datetable (daterange) VALUES('[@dateRangeStart, @dateRangeBegin]')";
  
  .... (standard connection stuff)
  
  var startDate = DateTime.Now;
  var endDate = DateTime.MaxValue;
  
  connection.Execute(INSERT_DATE_RANGE, new { @dateRangeStart = startDate, @dateRangeBegin = endDate });
  </code></pre>
  
  <p>This gives me the following error:</p>
  
  <blockquote>
    <p>22007: invalid input syntax for type date: "@dateRangeStart"</p>
  </blockquote>
  
  <p>I suspect this is because the parameters I'm trying to replace are inside the single quotes.  If I remove the quotes however, I get a different error message:</p>
  
  <blockquote>
    <p>42601: syntax error at or near "["</p>
  </blockquote>
  
  <p>Any suggestions?  I could just concatenate the string but I would prefer not to use that approach as it opens things up to a possible SQL injection.  </p>