Re: Elegant SQL solution: - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Elegant SQL solution:
Date
Msg-id 200306071854.30499.josh@agliodbs.com
Whole thread Raw
In response to Elegant SQL solution:  (Chris Gamache <cgg007@yahoo.com>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: greg@turnstep.com
Date:
Subject: Re: Elegant SQL solution:
Next
From: Tom Lane
Date:
Subject: Re: Changing owner of function -- best method?