On Friday 06 June 2003 18:26, Chris Gamache wrote:
> I could create a one-column table with values 1 - 12 in it, and select from
> that table with a where clause matching "month". I could also create a view
> "SELECT 1 UNION SELECT 2 UNION ..." and select against the view. There MUST
> be a more elegant way to do this.
You probably need a pivot table (the one-column table with values 1 - 12).
Oracle Magazine had a useful article on this subject (relevant for none-Oracle
SQL too) a while back: http://otn.oracle.com/oramag/oracle/02-sep/o52sql.html
(registration probably required).
Of course you could also use a set returning function a la:
CREATE OR REPLACE FUNCTION months() RETURNS SETOF INT AS ' BEGIN FOR i IN 1..12 LOOP RETURN NEXT i; END LOOP;
RETURN;
END;' LANGUAGE 'plpgsql';
Ian Barwick
barwick@gmx.net