From: Frank Bax <fbax@sympatico.ca>
Cc: pgsql-sql@postgresql.org
Subject: Re: counting related rows
Date: Fri, 8 Oct 2010 19:09:56 -0400
Message-ID: <BLU0-SMTP965F0BF4A84C81E4C7400BAC500@phx.gbl> (raw)
In-Reply-To: <m3r5g0filx.fsf@carbon.jhcloos.org>
References: <m3r5g0filx.fsf@carbon.jhcloos.org>
James Cloos wrote:
> I have a table which includes a text column containing posix-style
> paths. Ie, matching the regexp "^[^/]+(/[^/]+)*$".
>
> I need to do a query of a number of columns from that table, plus the
> count of rows which are "children" of the current row.
>
> The query:
>
> SELECT count(*) AS nch FROM m WHERE o = (SELECT o FROM m WHERE id=30016)
> AND name ILIKE (SELECT name || '/%' FROM m WHERE id=30016);
>
> selects that extra column given the id.
>
> A view containing all of the columns from m plus a column matching the
> above select would cover my needs well.
>
> But I haven't been able to get the syntax right.
It would help if you provided:
a) statements to create sample data
b) expected results from sample data
Does this do what you want?
select * from m, (SELECT count(*) AS nch FROM m WHERE o = (SELECT o FROM
m WHERE id=30016) AND name ILIKE (SELECT name || '/%' FROM m WHERE
id=30016)) om;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: fbax@sympatico.ca
Subject: Re: counting related rows
In-Reply-To: <BLU0-SMTP965F0BF4A84C81E4C7400BAC500@phx.gbl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox