title: IF ELSE in postgresql function
body: <p>I am trying to create a function which is as follows</p>
  <pre><code>create function public.getSomething(
          value1 integer
      )
        returns table (
               id integer,
               name varchar(20)
      
                ) as
      $$
      BEGIN
      
          IF value1 = 0 THEN
          
              select a.id, b.name from table1 a inner join table2 b on a.Something = b.Something where 
              a.column = something and b.column = something;
              
          END IF;
      
          IF value1 = 1 THEN
          
              select a.id, b.name from table1 a inner join table2 b on a.Something = b.Something where 
              a.column = something and b.column = something;
              
          END IF;
      
      END;
              
      $$ language SQL;
  </code></pre>
  <p>But when I am trying to Create, I am getting the following error</p>
  <pre><code>ERROR:  syntax error at or near &quot;if&quot; 
  </code></pre>
  <p>I tried changing the Language from SQL to plpgsql. But this time I am getting</p>
  <pre><code>Error: query has no destination for result data
  Hint: if you want to discard the results of a select use perform instead
  </code></pre>
  <p>then I replaced the <code>Select</code> with <code>Perform</code>. This time the function is created but when I am calling it
  There is no result!!</p>
  <p>What am I doing wrong? Is there any alternative? I am Using postgres version 12.3</p>