title: Representing Sparse Data in PostgreSQL
body: <p>What's the best way to represent a sparse data matrix in PostgreSQL? The two obvious methods I see are:</p>
  
  <ol>
  <li><p>Store data in a single a table with a separate column for every conceivable feature (potentially millions), but with a default value of NULL for unused features. This is conceptually very simple, but I know that with most RDMS implementations, that this is typically very inefficient, since the NULL values ususually takes up <em>some</em> space. However, I read an article (can't find its link unfortunately) that claimed PG doesn't take up data for NULL values, making it better suited for storing sparse data.</p></li>
  <li><p>Create separate "row" and "column" tables, as well as an intermediate table to link them and store the value for the column at that row. I believe this is the more traditional RDMS solution, but there's more complexity and overhead associated with it.</p></li>
  </ol>
  
  <p>I also found <a href="http://crypto.stanford.edu/portia/software/postgredynamic.html" rel="noreferrer">PostgreDynamic</a>, which claims to better support sparse data, but I don't want to switch my entire database server to a PG fork just for this feature.</p>
  
  <p>Are there any other solutions? Which one should I use?</p>