title: PostgreSQL checking dates and raising errors
body: <p>I have a table <code>car_rental</code> of which I am trying to check each tuple for overlapping dates, and RAISE an EXCEPTION error if these values overlap with my <code>check_date</code> function. But no matter what I do, I keep getting a syntax error on the first line of my function. What am I doing wrong?</p>
  
  <pre><code>CREATE FUNCTION check_date(IN i_sdate DATE, IN i_edate DATE, IN i_plate varchar(10), OUT overlap) 
    SET @i_sdate = start_date(i_sdate);
    SET @i_edate = end_date(i_edate);
    SET @i_plate = plate(i_plate);
    BEGIN
    SET overlap = SELECT CASE WHEN (
        (@i_sdate BETWEEN  start_date AND end_date AND @i_plate = plate FROM car_rental)OR
        (@i_edate BETWEEN start_date AND end_date AND AND @i_plate = plate FROM car_rental)OR
        (start_date BETWEEN @i_sdate AND @i_edate AND AND @i_plate = plate )
        THEN
        RAISE EXCEPTION 'unavailable --&gt; %', plate
              USING HINT = 'Car is unavailable';
        )
  </code></pre>