title: PL/pgSQL checking if a row exists
body: <p>I'm writing a function in PL/pgSQL, and I'm looking for the simplest way to check if a row exists.<br>
  Right now I'm SELECTing an <code>integer</code> into a <code>boolean</code>, which doesn't really work. I'm not experienced with PL/pgSQL enough yet to know the best way of doing this.</p>
  
  <p>Here's part of my function:</p>
  
  <pre><code>DECLARE person_exists boolean;
  BEGIN
  
  person_exists := FALSE;
  
  SELECT "person_id" INTO person_exists
    FROM "people" p
  WHERE p.person_id = my_person_id
  LIMIT 1;
  
  IF person_exists THEN
    -- Do something
  END IF;
  
  END; $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p><em>Update</em> - I'm doing something like this for now:</p>
  
  <pre><code>DECLARE person_exists integer;
  BEGIN
  
  person_exists := 0;
  
  SELECT count("person_id") INTO person_exists
    FROM "people" p
  WHERE p.person_id = my_person_id
  LIMIT 1;
  
  IF person_exists &lt; 1 THEN
    -- Do something
  END IF;
  </code></pre>