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.
The current code (which I did not write) uses one select to get the
values of id it wants, and then iterates through them selecting four
columns from the table and then the above. As you may imagine, two
selects per row is *slow*. Maybe 20 rows per second. I expect a
single, complete select to take < 10 ms.
Again, to be clear, for each row I need the count of other rows which
have the same value for column o and whose name is a child path of the
current row's name.
-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 1024D/ED7DAEA6