Re: Function as Phantom Field

Поиск
Список
Период
Сортировка
От tolik@aaanet.ru (Anatoly K. Lasareff)
Тема Re: Function as Phantom Field
Дата
Msg-id 868zrt3wkz.fsf@tolikus.hq.aaanet.ru
обсуждение исходный текст
Ответ на Function as Phantom Field  (Charles Tassell <ctassell@isn.net>)
Список pgsql-general
>>>>> "CT" == Charles Tassell <ctassell@isn.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@aaanet.ru

В списке pgsql-general по дате отправления:

Предыдущее
От: Henk van Lingen
Дата:
Сообщение: Re: cache lookup failed
Следующее
От: Michael Ansley
Дата:
Сообщение: RE: ODMG