X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id D7368F0029 for ; Sun, 8 Jun 2003 01:56:42 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 40435-02 for ; Sun, 8 Jun 2003 01:56:32 +0000 (GMT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by svr1.postgresql.org (Postfix) with ESMTP id 2FE0FF0099 for ; Sun, 8 Jun 2003 01:56:13 +0000 (GMT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3102057; Sat, 07 Jun 2003 18:56:11 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: cgg007@yahoo.com, pgsql-sql@postgresql.org Subject: Re: Elegant SQL solution: Date: Sat, 7 Jun 2003 18:54:30 -0700 User-Agent: KMail/1.4.3 References: <20030606162635.97132.qmail@web13807.mail.yahoo.com> In-Reply-To: <20030606162635.97132.qmail@web13807.mail.yahoo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200306071854.30499.josh@agliodbs.com> X-Archive-Number: 200306/49 X-Sequence-Number: 13807 CGG: > I could create a one-column table with values 1 - 12 in it, and select from > that table with a where clause matching "month". This is probably the simplest, most elegant solution. It is also the "most relational". > I could also create a view > "SELECT 1 UNION SELECT 2 UNION ..." and select against the view. This would be both awkward and have appaling performance. > There MUST > be a more elegant way to do this. Another method would be to write a set returning function that generates the months and corresponds them to a cursor of the totals and outputs that. However, I think your first method is likely to be the fastest and easiest to maintain. -- Josh Berkus Aglio Database Solutions San Francisco