From: | tolik(at)aaanet(dot)ru (Anatoly K(dot) Lasareff) |
---|---|
To: | Charles Tassell <ctassell(at)isn(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Function as Phantom Field |
Date: | 2000-10-13 09:43:40 |
Message-ID: | 868zrt3wkz.fsf@tolikus.hq.aaanet.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>>>>> "CT" == Charles Tassell <ctassell(at)isn(dot)net> writes:
CT> I have a database like this:
CT> CREATE TABLE articles (
CT> article_id serial primary key,
CT> title text
CT> );
CT> CREATE TABLE pages (
CT> article_id integer,
CT> page text
CT> );
CT> And I want to be able to do a
CT> SELECT article_id, title, count_pages(article_id) FROM articles
CT> Now, I have already written the count_pages function (it's just a count(*)
CT> where article_id = $1) but I don't know how to do the SELECT in one pass,
CT> is there some way I can do this with triggers or is there a special field
CT> name I can use to specify the current article_id as the function argument?
Try this:
select articles.article_id, count(*) from articles, pages where
article.article_id = pages.article_id group by pages.article_id;
--
Anatoly K. Lasareff Email: tolik(at)aaanet(dot)ru
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Ansley | 2000-10-13 10:50:46 | RE: ODMG |
Previous Message | Henk van Lingen | 2000-10-13 08:31:49 | Re: cache lookup failed |