title: PostgreSQL: Return NULL values for dates that do not exist
body: <p>This query works except it does not return records for the dates (time_added) that bx_broker doesn't have data:</p>
  
  <pre><code>select bx_broker as Broker, date_trunc('day', time_added) as date, avg(bx_avgpxvsarrival) as AvgPr_vs_Arrival, avg(bx_avgpxvsoppvwapbpsblackrockasia) as AvgPr_vs_VWAP
  from best_ex_data
  where bx_broker = 'ML'
  group by date_trunc('day', time_added), bx_broker
  order by date desc
  limit 365;
  </code></pre>
  
  <p>For example if there are lots of records in my data set for bx_broker = 'ML' on all the time_added dates, but only a few for bx_broker = 'XYZ' on the time_added dates I currently get fewer records for bx_broker = 'XYZ'.  I want to always force the dates to have a record for bx_broker even if there isn't data on that day. The dates without data would be NULL for all fields other than date, but the dates would still be there in the query results with NULL values for all other fields.  I want separate results for each bx_broker (i.e. I will be rerunning the query for each bx_broker).</p>
  
  <p>Thank you for your help!</p>
  
  <p>Edit:</p>
  
  <p>Here are the results of my query for a bx_broker = ML with data for all dates in my best_ex_data table:</p>
  
  <pre><code>╔════════╦════════════╦══════════════════╦═══════════════╗
  ║ broker ║    date    ║ avgpr_vs_arrival ║ avgpr_vs_vwap ║
  ╠════════╬════════════╬══════════════════╬═══════════════╣
  ║ ML     ║ 2016-12-12 ║ 0.00             ║ 0.63          ║
  ║ ML     ║ 2016-12-09 ║ -0.06            ║ -1.74         ║
  ║ ML     ║ 2016-12-08 ║ 0.10             ║ -8.11         ║
  ║ ML     ║ 2016-12-07 ║ -0.40            ║ -9.55         ║
  ║ ML     ║ 2016-12-06 ║ -0.29            ║ -8.84         ║
  ║ ML     ║ 2016-12-05 ║ -0.15            ║ -3.47         ║
  ║ ML     ║ 2016-12-02 ║ 0.23             ║ -4.70         ║
  ╚════════╩════════════╩══════════════════╩═══════════════╝
  </code></pre>
  
  <p>Here are the results of my query for a bx_broker = GSEC that does not have data for all dates:</p>
  
  <pre><code>╔════════╦════════════╦══════════════════╦═══════════════╗
  ║ broker ║    date    ║ avgpr_vs_arrival ║ avgpr_vs_vwap ║
  ╠════════╬════════════╬══════════════════╬═══════════════╣
  ║ GSEC   ║ 2016-12-09 ║ -0.04            ║ -0.66         ║
  ║ GSEC   ║ 2016-12-07 ║ 0.01             ║ 1.59          ║
  ║ GSEC   ║ 2016-12-06 ║ -0.06            ║ -1.43         ║
  ║ GSEC   ║ 2016-12-05 ║ 0.01             ║ -0.25         ║
  ║ GSEC   ║ 2016-12-02 ║ -0.09            ║ -2.06         ║
  ╚════════╩════════════╩══════════════════╩═══════════════╝
  </code></pre>
  
  <p>Here is what I would like for bx_broker = GSEC (note the addition of dates that exist in the table even if GSEC doesn't have data):</p>
  
  <pre><code>╔════════╦════════════╦══════════════════╦═══════════════╗
  ║ broker ║    date    ║ avgpr_vs_arrival ║ avgpr_vs_vwap ║
  ╠════════╬════════════╬══════════════════╬═══════════════╣
  ║ GSEC   ║ 2016-12-12 ║                  ║               ║
  ║ GSEC   ║ 2016-12-09 ║ -0.04            ║ -0.66         ║
  ║ GSEC   ║ 2016-12-08 ║                  ║               ║
  ║ GSEC   ║ 2016-12-07 ║ 0.01             ║ 1.59          ║
  ║ GSEC   ║ 2016-12-06 ║ -0.06            ║ -1.43         ║
  ║ GSEC   ║ 2016-12-05 ║ 0.01             ║ -0.25         ║
  ║ GSEC   ║ 2016-12-02 ║ -0.09            ║ -2.06         ║
  ╚════════╩════════════╩══════════════════╩═══════════════╝
  </code></pre>
  
  <p>Note: When I run the query I don't know that any one broker has data for all of the dates. I think I have to select all of the dates and do some outer join with that and a broker specific select.</p>