reasoncorp/dossier

crosstab example

Opened this issue · 0 comments

I've got a number of basic queries working and found the gem to be quite useful.

However, I have the following crosstab query:

class OverflowPivotReport < Dossier::Report
  def sql
    '
    SELECT * FROM crosstab('
        SELECT zip, status, status_count
        FROM "status_counts"
        ORDER BY 1, 2;')
    AS ct (zip character varying, "0" bigint, "1" bigint, "2" bigint, "8" bigint);
    '
  end
end

status_counts is a DB view.
when I run the query directly on the DB it works fine.

I get the following error when I run the .html report:

undefined local variable or method `zip' for #<OverflowPivotReport:0x007fc2dd1cacd0>

I saw the following in the documentation:

Show how to do "crosstab" reports (preliminary query to determine columns, then build SQL case statements?)

Not sure where to go from here...