Re: Aggregating over nodes in hierarchical trees

From: hari(dot)fuchs(at)gmail(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Aggregating over nodes in hierarchical trees
Date: 2014-09-11 08:23:51
Message-ID: 87iokuzht4.fsf@hf.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"McGehee, Robert" <Robert(dot)McGehee(at)geodecapital(dot)com> writes:

> SELECT n.node, sum(students) as students
> FROM tree_tbl t, node_tbl n
> WHERE t.course ~ '.*' || n.node || '.*'
> GROUP BY n.node;

I'd write this as

SELECT n.node, sum(students) AS students
FROM tree_tbl t
JOIN node_tbl n ON t.course ~ ('*.' || n.node || '.*')::lquery
GROUP BY n.node;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Iain Mott 2014-09-11 10:49:51 permission denied for schema topology
Previous Message damien clochard 2014-09-11 07:36:18 Re: Introducing Open PostgreSQL Monitoring (OPM)