Re: [SQL] Re: [SQL] need some magic with generate_series()

2013-01-23 Thread Andreas
I'm sorry to prove that daft. :( generate_series needs the startdate of every project to generate the specific list of monthnumbers for every project. To join against this the list needs to have a column with the project_id. So I get something like this but still I cant reference the columns

[SQL] Re: [SQL] need some magic with generate_series()

2013-01-22 Thread Alexander Gataric
Create a CTE with the project code and starting month of the project. Left join to month series CTE. Sent from my smartphone - Reply message - From: "Andreas" To: "Alexander Gataric" Cc: "Filip Rembiałkowski" , "jan zimmek" , Subject: [SQL] need some magic with generate_series() Date

Re: [SQL] need some magic with generate_series()

2013-01-22 Thread Andreas
The query should work for all projects in the projects table where everyone has a seperate startdate for the series. For the join I need ( project_id, month_nr ). When I tried I couldn't figure out how to feed the startdate into Filip's expression without using the function to encapsulate the

[SQL] Re: [SQL] need some magic with generate_series()

2013-01-22 Thread Alexander Gataric
I would create a common table expression with the series from Filip and left join to the table you need to report on. Sent from my smartphone - Reply message - From: "Andreas" To: "Filip Rembiałkowski" Cc: "jan zimmek" , Subject: [SQL] need some magic with generate_series() Date: Tue,

Re: [SQL] need some magic with generate_series()

2013-01-22 Thread Andreas
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, 'MM' )::integer fromgenerate_series ( $1, current_date,

Re: [SQL] need some magic with generate_series()

2013-01-22 Thread 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

Re: [SQL] need some magic with generate_series()

2013-01-22 Thread jan zimmek
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, 2013