title: function to provide id of interval the input is located between
body: <p>I want to create a function that will receive a date as input and be able to provide back the id of the corresponding interval that it's located in.</p>
  <p>For example with this table here:</p>
  <pre><code>  id |   start    |    end   
    -- +------------+------------
  
    1  | 2000-11-30 | 2001-02-19
  
    2  | 2001-02-21 | 2001-06-04
  
    3  | 2001-06-05 | 2001-07-13
  
    4  | 2001-07-15 | 2001-11-29
  </code></pre>
  <p>If i input the date '2001-04-17', i want it to return back the id value of 2.</p>
  <p>i'm currently trying this currently but can't get it to work:</p>
  <pre><code>create or replace function getId(_date date) returns integer
  as $$
  declare
      myId integer;
  begin
      set myId = (select id from myTable 
          where ((_date &gt;= start) and (_date &lt;= end)));
  
      return myId;
  end;
  $$ language plpgsql
  ;
  </code></pre>