pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brent Wood <pcreso@yahoo.com>
To: a <372660931@qq.com>
To: pgsql-general <pgsql-general@postgresql.org>
To: 372660931@qq.com <372660931@qq.com>
Subject: Re: Ways to deal with large amount of columns;
Date: Fri, 31 Aug 2018 09:31:55 +0000 (UTC)
Message-ID: <1318288365.1390440.1535707915942@mail.yahoo.com> (raw)
In-Reply-To: <tencent_74B211A80785C27C5C3C58D8@qq.com>
References: <tencent_74B211A80785C27C5C3C58D8@qq.com>

You need to normalise your data model... the basic dataset you describe will probably fit in one table with three columns, but that might be simplistic...

All your aggregate queries are pretty basic SQL statements, which could be represented as views or made simpler to invoke by turning them into functions.

So, one table describing agents, with columns for agent, date and projected cashflow will store all your data...
(index agent & date for performance)
eg: for a summary for all agents for the last 12 months:
select agent, sum(cashflow) 
from tablewhere date >= now() - interval '1 year'group by agentorder by agent;

or a cashflow aggregate summary for the latest month
select sum(cashflow), avg(cashflow), min(cashflow), max(cashflow)  
from table 
where date = (select max(date) from table);

or get the agent with highest projected cashflow for the latest month
select agentfrom tablewhere date = (select max(date) from table)  and cashflow=(select max(cashflow) from table 
      where date = (select max(date) from table));


      From: a <372660931@qq.com>
 To: pgsql-general <pgsql-general@postgresql.org> 
 Sent: Thursday, August 30, 2018 9:14 PM
 Subject: Ways to deal with large amount of columns;
   
Hi all:
I need to make a table contains projected monthly cashflow for multiple agents (10,000 around).
Therefore, the column number would be 1000+. 
I would need to perform simple aggregate function such as count, sum or average on each cashflow projected.
So if there is anyway of doing this? Will there be anything like define a macro in C that I can manipulate multiple columns by simple word that representing them.

Thanks so much!
Shore

   

view thread (11+ messages)

Message-ID: <1318288365.1390440.1535707915942@mail.yahoo.com>
Permalink:  ../1318288365.1390440.1535707915942@mail.yahoo.com/
Also on:    postgresql.org/message-id/1318288365.1390440.1535707915942@mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: pcreso@yahoo.com, 372660931@qq.com
  Subject: Re: Ways to deal with large amount of columns;
  In-Reply-To: <1318288365.1390440.1535707915942@mail.yahoo.com>
  References: <tencent_74B211A80785C27C5C3C58D8@qq.com> <1318288365.1390440.1535707915942@mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox