Skip to content

Instantly share code, notes, and snippets.

@michelp
Created April 2, 2015 02:04
Show Gist options
  • Select an option

  • Save michelp/183f46239ffc50bfc724 to your computer and use it in GitHub Desktop.

Select an option

Save michelp/183f46239ffc50bfc724 to your computer and use it in GitHub Desktop.
create type search.amounts_by_code as (total integer, purpose_code text);
create or replace function search.amount_by_code(auser text, apath jsonb, args jsonb)
returns setof search.amounts_by_code as $$
select (sum(amount), purpose_codes)::search.amounts_by_code
from working_transactions
where tran_date > '2012-01-01' and tran_date < '2013-01-01'
and filer ilike '%' || (apath->>0) || '%'
group by purpose_codes order by sum(amount) desc;
$$ language sql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment