Skip site navigation (1) Skip section navigation (2)

Performing a sub-query in a SELECT SUM aggregate.

From: "Peter Geoghegan" <peter(dot)geoghegan86(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Performing a sub-query in a SELECT SUM aggregate.
Date: 2008-04-30 12:19:00
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general

I'm writing a large pl/pgSQL function to batch process raw sales
records into departmentalised totals, stored in a dedicated table. The
logical thing to do is to INSERT a conditional aggregate ( INSERT INTO
that dedicated table.

However, I need to do things like INSERT special records into some
other table sometimes. For example, if the sales were made on credit,
I need to make a dedicated record of that in the credit accounts
table. I'd like to do this within the conditional aggregate, when it
encounters a record that requires it, because that's more logical,
direct and efficient, rather then do the aggregate and then do
separate,"special" things on the same data. Is this possible? If not,
could someone write some psuedo code that would accomplish the same
think efficiently using cursors or something?


Peter Geoghegan

pgsql-general by date

Next:From: Tatsuo IshiiDate: 2008-04-30 12:26:06
Subject: Re: Multibyte (Japanese Character) Sorting
Previous:From: Gurjeet SinghDate: 2008-04-30 11:30:16
Subject: Re: inheritance. more.

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group