From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | Marcos Hercules Santos <mhercs(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: function on trigger |
Date: | 2011-09-01 04:20:25 |
Message-ID: | 23226B29-9B3A-4778-B7C2-7C990897B712@yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Aug 31, 2011, at 18:39, Marcos Hercules Santos <mhercs(at)gmail(dot)com> wrote:
> hi guys
>
> I'm newbie in Psql and I'm trying to build one function in order to
> count the products for each supplier. So i'm gonna put it quite simply
> though this example
>
>
> Please, consider a table called books with the following fields
>
> bookid, title, price, idPublisher
>
>
>
> and one another table called publisher
>
> Idpublisher, name, city, Books
>
>
> Being in that last field from Publisher, called book, I gotta have the
> amount of published books for each publisher.
Is there a question somewhere?
>
Do not be tempted by the dark side Marcos. Create a view that uses a join and a count. Only if you have significant performance issues would you then consider materializing that view.
If you insist, or simply want to learn, read the sections on UPDATE, CREATE TRIGGER, and CREATE FUNCTION. Try doing it following those examples. Ask more specific questions if something specific stumps you.
Do it incrementally. Get the raw SQL UPDATE working then create the trigger and function and get those working. Then combine the two.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Sim Zacks | 2011-09-01 04:46:19 | Re: function on trigger |
Previous Message | Lou Picciano | 2011-09-01 03:00:55 | Re: toast error after pg_upgrade 9.0.4 -> 9.1rc1 |