Re: Function as Phantom Field

From: Tomas Berndtsson <tomas(at)nocrew(dot)org>
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 08:07:01
Message-ID: 804s2hb1wa.fsf@junk.nocrew.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Charles Tassell <ctassell(at)isn(dot)net> writes:

> I have a database like this:
>
> CREATE TABLE articles (
> article_id serial primary key,
> title text
> );
>
> CREATE TABLE pages (
> article_id integer,
> page text
> );
>
> And I want to be able to do a
>
> SELECT article_id, title, count_pages(article_id) FROM articles
>
> Now, I have already written the count_pages function (it's just a count(*)
> where article_id = $1) but I don't know how to do the SELECT in one pass,
> is there some way I can do this with triggers or is there a special field
> name I can use to specify the current article_id as the function argument?

I'm not sure I understand what you want to do, but maybe a GROUP BY is
what you're looking for:

SELECT article_id, title, count_pages(article_id)
FROM articles
GROUP BY article_id, title

Tomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dan Moschuk 2000-10-13 08:19:47 Re: Re: [HACKERS] My new job
Previous Message Charles Tassell 2000-10-13 07:40:11 Function as Phantom Field