How to write a crosstab which returns empty row results - Mailing list pgsql-general

From David Goldsmith
Subject How to write a crosstab which returns empty row results
Date
Msg-id CAFtPsZqfiRvRp1EngwEfyNMu=nW11C0i7WvtYtBpO0gjjwLPwQ@mail.gmail.com
Whole thread Raw
Responses Re: How to write a crosstab which returns empty row results
List pgsql-general
Hi. New subscriber and intermediate level SQL writer here, still pretty new to Postgresql (but I don't know how to do the following in TSQL either).

I've figured out how to write a crosstab query I need; the problem is that the number of row results should be 72, but I'm only getting 41.  I'm pretty sure this is because there actually isn't any data matching my where constraints for the 31 missing row header values, but I nevertheless need them in my result, with NULLs where there is no data.  How do I force "empty rows" to be included in my query output? (I've tried LEFT JOINing to the row header results, and using CASE statements; but due to my unfamiliarity w/ using crosstab, I'm not sure if I've used those correctly in the current context; so if using either or both of those is part of the solution, please do more than simply saying "use a Left join" or "use a case statement," i.e., furnish an example, please.

Thanks!

pgsql-general by date:

Previous
From: Brad White
Date:
Subject: Re: Implementing foreign data wrappers and avoiding n+1 querying
Next
From: Brad White
Date:
Subject: Re: How to write a crosstab which returns empty row results