Re: Generating a SQL Server population routine
От | Harald Fuchs |
---|---|
Тема | Re: Generating a SQL Server population routine |
Дата | |
Msg-id | puekxmvllp.fsf@srv.protecting.net обсуждение исходный текст |
Ответ на | Generating a SQL Server population routine (Martin_Hurst@dom.com) |
Список | pgsql-general |
In article <64591.66.212.203.144.1065659357.squirrel@$HOSTNAME>, <btober@seaworthysys.com> writes: > Or a little different, with the over-loaded functions relying on the > original: > CREATE OR REPLACE FUNCTION public.enum(int4) RETURNS SETOF int4 AS ' > DECLARE > numvals ALIAS FOR $1; > BEGIN > FOR currval IN 0 .. numvals - 1 LOOP > RETURN NEXT currval; > END LOOP; > RETURN; > END; > ' LANGUAGE 'plpgsql' VOLATILE; Why VOLATILE? Shouldn't that be IMMUTABLE? (Sorry, but I'm a PostgreSQL newbie.) > But, as interesting as these look, what would you actually use them for? SELECT extract (month FROM sdate) AS month, count (*) AS monthly_sales FROM sales GROUP BY month ORDER BY month; gives you the monthly sales, but what if you would like a result row also for months with nothing sold? SELECT enum, count (sdate) AS monthly_sales FROM enum (12, 1) LEFT JOIN sales ON enum = extract (month FROM sdate) GROUP BY enum ORDER BY enum; This would do the trick. Is there a more elegant solution?
В списке pgsql-general по дате отправления: