Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Txmbu-0003YJ-2d for pgsql-sql@arkaria.postgresql.org; Tue, 22 Jan 2013 22:46:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Txmbs-0001WL-VP for pgsql-sql@arkaria.postgresql.org; Tue, 22 Jan 2013 22:46:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Txmbs-0001WF-2P for pgsql-sql@postgresql.org; Tue, 22 Jan 2013 22:46:28 +0000 Received: from mout.gmx.net ([212.227.17.21]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Txmbp-0008Tv-8W for pgsql-sql@postgresql.org; Tue, 22 Jan 2013 22:46:27 +0000 Received: from mailout-de.gmx.net ([10.1.76.32]) by mrigmx.server.lan (mrigmx002) with ESMTP (Nemesis) id 0Ll3wB-1TNLOf1TCn-00apcQ for ; Tue, 22 Jan 2013 23:46:24 +0100 Received: (qmail invoked by alias); 22 Jan 2013 22:46:24 -0000 Received: from mue-88-130-23-112.dsl.tropolys.de (EHLO [192.168.1.113]) [88.130.23.112] by mail.gmx.net (mp032) with SMTP; 22 Jan 2013 23:46:24 +0100 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1/Ur7Zgnz3UW9cT8aI/jiHLVyzyMPx2iHC5FuAjnc GWkcTOildvu4U/ Message-ID: <50FF177C.4000800@gmx.net> Date: Tue, 22 Jan 2013 23:49:32 +0100 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: =?UTF-8?B?RmlsaXAgUmVtYmlhxYJrb3dza2k=?= CC: jan zimmek , pgsql-sql@postgresql.org Subject: Re: need some magic with generate_series() References: <50FF0784.1070205@gmx.net> <1B56ACCA-3259-4AF6-9EBA-7045E261B18F@web.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Thanks Filip, with your help I came a step further. :) Could I do the folowing without using a function? CREATE OR REPLACE FUNCTION month_series ( date ) RETURNS table ( monthnr integer ) AS $BODY$ select to_char ( m, 'YYYYMM' )::integer from generate_series ( $1, current_date, '1 month'::interval ) as m $BODY$ LANGUAGE sql STABLE; select project_id, month_series ( createdate ) from projects order by 1, 2; Am 22.01.2013 22:52, schrieb Filip RembiaƂkowski: > or even > > select m from generate_series( '20121101'::date, '20130101'::date, '1 > month'::interval) m; > > > > On Tue, Jan 22, 2013 at 3:49 PM, jan zimmek wrote: >> hi andreas, >> >> this might give you an idea how to generate series of dates (or other datatypes): >> >> select g, (current_date + (g||' month')::interval)::date from generate_series(1,12) g; >> >> regards >> jan >> >> Am 22.01.2013 um 22:41 schrieb Andreas : >> >>> Hi >>> I need a series of month numbers like 201212, 201301 YYYYMM to join other sources against it. >>> >>> I've got a table that describes projects: >>> projects ( id INT, project TEXT, startdate DATE ) >>> >>> and some others that log events >>> events( project_id INT, createdate DATE, ...) >>> >>> to show some statistics I have to count events and present it as a view with the project name and the month as YYYYMM starting with startdate of the projects. >>> >>> My problem is that there probaply arent any events in a month but I still need this line in the output. >>> So somehow I need to have a select that generates: >>> >>> project 7,201211 >>> project 7,201212 >>> project 7,201301 >>> >>> It'd be utterly cool to get this for every project in the projects table with one select. >>> >>> Is there hope? >>> >>> >>> -- >>> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) >>> To make changes to your subscription: >>> http://www.postgresql.org/mailpref/pgsql-sql >> >> >> -- >> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-sql -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql