From: | Harald Fuchs <nospam(at)sap(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Generating a SQL Server population routine |
Date: | 2003-10-09 08:52:50 |
Message-ID: | puekxmvllp.fsf@srv.protecting.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
In article <64591(dot)66(dot)212(dot)203(dot)144(dot)1065659357(dot)squirrel(at)$HOSTNAME>,
<btober(at)seaworthysys(dot)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?
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2003-10-09 09:02:58 | Re: autoupdate sequences after copy |
Previous Message | Ang Chin Han | 2003-10-09 08:44:03 | Re: Does postgresql support HKSCS ? |