Re: need some magic with generate_series()

From: Filip Rembiałkowski <plk(dot)zuber(at)gmail(dot)com>
To: jan zimmek <jan(dot)zimmek(at)web(dot)de>
Cc: Andreas <maps(dot)on(at)gmx(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: need some magic with generate_series()
Date: 2013-01-22 21:52:48
Message-ID: CAP_rwwk-5rLunfBgFUXNJZ+_XW54krB+FKVLbs5R1Nby6r1a4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 <jan(dot)zimmek(at)web(dot)de> 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 <maps(dot)on(at)gmx(dot)net>:
>
>> 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(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-sql
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas 2013-01-22 22:49:32 Re: need some magic with generate_series()
Previous Message jan zimmek 2013-01-22 21:49:56 Re: need some magic with generate_series()