title: How to compare two rows in postgresql?
body: <p>I have a table <code>tab</code> that contaions:</p>
  
  <pre><code>item identifier quantity methodid
  10      1         20         2
  10      1         30         3
  11      1         10         3
  11      1         12.5       3
  11      2         20         5
  12      1         20         1
  12      1         30         1
  </code></pre>
  
  <p>I need to write a function that checks if there is a case of duplicate <code>methodid</code> for <code>item</code> and <code>identifier</code>.
  In the above example  <code>item</code> 11 <code>identifier</code> 1 has two rows of <code>methodid</code> 3 means it's duplicated, also <code>item</code> 12 <code>idfentifier</code> 1 has duplicated rows as well.</p>
  
  <p>I don't need to do anything to the data just to identify this situation.</p>
  
  <p>I don't need to find where and what was duplicated... just tell there is duplication. </p>
  
  <p>The only information I have is the <code>identifier</code></p>
  
  <pre><code>  CREATE OR REPLACE FUNCTION func(identifier integer)
        RETURNS integer AS
      $BODY$
      declare
      errorcode int;
      begin
          if _____________   then
              errorcode =1;
              raise exception 'there id duplication in this identifier';  
          END IF;
  
          continue work
  
          return 0;           
          exception
              when raise_exception then
      return errorcode;
      end;                
      $BODY$
      LANGUAGE plpgsql VOLATILE
  </code></pre>
  
  <p>in the blank spot I want to put a query that checks for duplications.</p>
  
  <p>How do I write a query that perform the check?
  The structure of function can be changed. but I need somehow to know when to raise the exception.</p>