title: How to write function for optional parameters in postgresql?
body: <p>My requirement is write optional parameters to a function.Parameters are optional sometimes i will add or i will not pass parameters to function.Can anyone help me how to write function.</p>
  
  <p>I am writing like </p>
  
  <pre><code>select * 
  from test 
  where field3 in ('value1','value2') 
   and ($1 is null or field1 = $1) 
   and ($2 is null or field2 = $2) 
   and ($3 is null or field3 = $3);
  </code></pre>
  
  <p>i am passing parameters to Query,But my output is not expected.when i pass all three parameters my output is correct,otherwise it is not expected output.</p>