Re: To get a Table or View like a Calendar with dates

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: To get a Table or View like a Calendar with dates
Date: 2012-08-11 17:04:55
Message-ID: 20120811170455.GA5906@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Csanyi Pal <csanyipal(at)gmail(dot)com> wrote:

> OK, I have an initial question.
>
> The start date and the end date of the first half part of school year
> are in two different tables in my database.
>
> How can I get rows in a view between those two dates?

Okay, you have the start- and end-date in 2 different tables? No
problem:

test=*# select * from t_start ;
d
------------
2012-01-01
(1 row)

Time: 0,196 ms
test=*# select * from t_end;
d
------------
2012-01-10
(1 row)

Time: 0,240 ms
test=*# select (d + s * '1day'::interval)::date from t_start,
generate_series(0, ((select d from t_end) - (select d from t_start)))s;
date
------------
2012-01-01
2012-01-02
2012-01-03
2012-01-04
2012-01-05
2012-01-06
2012-01-07
2012-01-08
2012-01-09
2012-01-10
(10 rows)

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Csanyi Pal 2012-08-11 19:29:43 Re: To get a Table or View like a Calendar with dates
Previous Message Csanyi Pal 2012-08-11 13:21:04 Re: To get a Table or View like a Calendar with dates