Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/db/sql/materialized views/process_bills_from_snapshot_mv.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,20 @@ full_history AS (
),

-- Process bill sponsors to get primary author and coauthors
-- Updated to handle cases when primary_author column is blank (when it is blank, then full_name
-- is blank and we need to use 'name' column instead of full_name, and also use title to distinguish
-- b/w authors and coauthors)
bill_authors AS (
SELECT
openstates_bill_id,
MAX(CASE WHEN primary_author = 'True' THEN full_name END) AS author,
STRING_AGG(CASE WHEN primary_author = 'False' THEN full_name END, ', ') AS coauthors
COALESCE(
MAX(CASE WHEN primary_author = 'True' THEN full_name END),
MAX(CASE WHEN (primary_author IS NULL OR primary_author = '') AND title = 'author' THEN name END)
) AS author,
COALESCE(
STRING_AGG(CASE WHEN primary_author = 'False' THEN full_name END, ', '),
STRING_AGG(CASE WHEN (primary_author IS NULL OR primary_author = '') AND title != 'author' THEN name END, ', ')
) AS coauthors
FROM snapshot.bill_sponsor
GROUP BY openstates_bill_id
),
Expand Down