title: SQL - if-statement in function
body: <p>I have some trouble with an if-statement in my function.
  I'm getting </p>
  
  <pre><code>ERROR: Syntaxfehler bei »if«
  SQL Status:42601
  Zeichen:78
  </code></pre>
  
  <p>I'm trying to get the data between two dates. If there is no date-Input, I want to get all the data. 
  The code looks like this</p>
  
  <pre><code>create or replace function datacut(DATE, DATE)
  returns record AS $$
  if $1 = ''
  then
  select * from hist_point;
  else
  SELECT *
  from hist_point h
  Where h.valid_from &lt; $2 AND h.valid_from &gt;= $1;
  end if;
  $$ LANGUAGE SQL;
  </code></pre>
  
  <p>This is just a prototyp for some other functions.</p>
  
  <p>Any sort of tip, hint or help is welcome.</p>
  
  <p>Thanks in advance. </p>