title: select all rows tagged with a list of tags
body: <p>I came up with this query to find all people that where tagged with a certain list of tags:</p>
  
  <pre><code>select * from people
  where ARRAY[?]::character varying[] &lt;@ ARRAY(
        select tags.name
        from tags
        inner join taggings on tags.id = taggings.tag_id
        where taggings.taggable_type = 'Person' and
              taggings.taggable_id = people.id)
  </code></pre>
  
  <p>Somehow I feel I'm making things too complicated. Right now we don't have enough data for this not to perform well, but is there really not a better way to do it?</p>
  
  <p><strong>Edit:</strong> Minimal table definitions:</p>
  
  <pre><code>create table people (
      id integer
  );
  
  create table tags (
      id integer,
      name text
  );
  
  create table taggings (
      id integer,
      tag_id integer,
      taggalbe_type text,
      taggable_id integer
  );
  </code></pre>
  
  <p>Minimal data:</p>
  
  <pre><code>insert into people values (1);
  insert into people values (2);
  insert into people values (3);
  
  insert into tags values (1, 'foo');
  insert into tags values (2, 'bar');
  insert into tags values (3, 'baz');
  
  insert into taggings values (1, 1, 'Person', 1);
  insert into taggings values (2, 2, 'Person', 1);
  insert into taggings values (3, 1, 'Person', 2);
  insert into taggings values (4, 2, 'Person', 2);
  insert into taggings values (5, 3, 'Person', 2);
  </code></pre>
  
  <p>Now I want e.g. everyone that is tagged with <code>foo</code> and <code>bar</code>. That would be the person with id 2 in this example.</p>