dbTalk Databases Forums  

[NOVICE] To get a Table or View like a Calendar with dates

mailing.database.pgsql-novice mailing.database.pgsql-novice


Discuss [NOVICE] To get a Table or View like a Calendar with dates in the mailing.database.pgsql-novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Csanyi Pal
 
Posts: n/a

Default [NOVICE] To get a Table or View like a Calendar with dates - 08-04-2012 , 03:24 PM






Hi,

I'm trying to explain what I want to achieve with my postgresql
database.

The database should store the data like dates of the beginning and the
end of the school year, holidays, non school days, various events, etc.

I want to get a Table or a View which I can use as a School Calendar
with school days, and non school days too, and much more.

I have created Tables with dates of the beginning date and the end date
of the school year.

I have Table with dates of holidays and/or non school days in the school
year too.

Can I create a Table or a View from these Tables to get such a school
calendar?

--
Regards from Pal


--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #2  
Old   
Kevin Grittner
 
Posts: n/a

Default Re: [NOVICE] To get a Table or View like a Calendar with dates - 08-06-2012 , 11:08 AM






Csanyi Pal <csanyipal (AT) gmail (DOT) com> wrote:

Quote:
The database should store the data like dates of the beginning and
the end of the school year, holidays, non school days, various
events, etc.

I want to get a Table or a View which I can use as a School
Calendar with school days, and non school days too, and much more.

I have created Tables with dates of the beginning date and the end
date of the school year.

I have Table with dates of holidays and/or non school days in the
school year too.

Can I create a Table or a View from these Tables to get such a
school calendar?
Yes, it sounds like the set of tables you describe could support a
great many useful queries, and you could encapsulate these in views
to make them easier to use.

Are you having some problem doing so? What have you tried? What
did you expect to happen? What happened instead?

-Kevin

--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #3  
Old   
Csanyi Pal
 
Posts: n/a

Default Re: [NOVICE] To get a Table or View like a Calendar with dates - 08-11-2012 , 08:21 AM



Hi Kevin,

"Kevin Grittner" <Kevin.Grittner (AT) wicourts (DOT) gov> writes:

Quote:
Csanyi Pal <csanyipal (AT) gmail (DOT) com> wrote:

The database should store the data like dates of the beginning and
the end of the school year, holidays, non school days, various
events, etc.

I want to get a Table or a View which I can use as a School
Calendar with school days, and non school days too, and much more.

I have created Tables with dates of the beginning date and the end
date of the school year.

I have Table with dates of holidays and/or non school days in the
school year too.

Can I create a Table or a View from these Tables to get such a
school calendar?

Yes, it sounds like the set of tables you describe could support a
great many useful queries, and you could encapsulate these in views
to make them easier to use.

Are you having some problem doing so? What have you tried? What
did you expect to happen? What happened instead?
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?

I expect to get rows like:
date1 weekday1
date2 weekday2
..
datex weekdayx

where 'date1' should to be the first day in the school year and 'datex'
should to be the last day in the first part of school year.

If I can get these rows in a view then I can after that modify the view
so I get extended informations like holidays if such occures in that
range of dates, etc.

--
Regards from Pal


-
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #4  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: [NOVICE] To get a Table or View like a Calendar with dates - 08-11-2012 , 12:04 PM



Csanyi Pal <csanyipal (AT) gmail (DOT) com> wrote:

Quote:
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°

-
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #5  
Old   
Csanyi Pal
 
Posts: n/a

Default Re: [NOVICE] To get a Table or View like a Calendar with dates - 08-11-2012 , 02:29 PM



Hi Andreas,

Andreas Kretschmer <akretschmer (AT) spamfence (DOT) net> writes:

Quote:
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;
I tried the followings:

iskolanaptar_201213=# select (datum + s * '1day'::interval)::date from
felevek_kezdetei_1_8, generate_series(0, ((select datum from
felev1_vege_tan_nap_1_8) - (select datum from felevek_kezdetei_1_8 where
felev1v2 = '1')))s;

and get:

date
------------
2012-09-03
2013-01-15
2012-09-04
2013-01-16
2012-09-05
2013-01-17
2012-09-06
2013-01-18

..

2012-12-19
2013-05-02
2012-12-20
2013-05-03
2012-12-21
2013-05-04
(220 rows)

So this isn't what I expected because I get dates from the both half
school years and not just from the first one.

In the table 'felevek_kezdetei_1_8' I have two columns:
'felev1v2' and 'datum':

felev1v2 | datum
----------+------------
1 | 2012-09-03
2 | 2013-01-15
(2 rows)

The meaning of the 'felev1v2 = 1' is that that the first half of the
school year beginning at 2012-09-03.

To get date intervall only from the first half school year I tried the
command:

iskolanaptar_201213=# select (datum + s * '1day'::interval)::napok from
felevek_kezdetei_1_8 where felev1v2 = '1', generate_series(0, ((select
datum from felev1_vege_tan_nap_1_8) - (select datum from
felevek_kezdetei_1_8 where felev1v2 = '1')))s;
ERROR: syntax error at or near ","
LINE 1: ...pok from felevek_kezdetei_1_8 where felev1v2 = '1',
generate...

What cause this error and what is the proper command here?

--
Regards from Pal


-
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #6  
Old   
Csanyi Pal
 
Posts: n/a

Default Re: [NOVICE] To get a Table or View like a Calendar with dates - 08-15-2012 , 03:07 PM



Hi Kevin,

"Kevin Grittner" <Kevin.Grittner (AT) wicourts (DOT) gov> writes:

Quote:
Csanyi Pal <csanyipal (AT) gmail (DOT) com> wrote:

The database should store the data like dates of the beginning and
the end of the school year, holidays, non school days, various
events, etc.

I want to get a Table or a View which I can use as a School
Calendar with school days, and non school days too, and much more.

I have created Tables with dates of the beginning date and the end
date of the school year.

I have Table with dates of holidays and/or non school days in the
school year too.

Can I create a Table or a View from these Tables to get such a
school calendar?

Yes, it sounds like the set of tables you describe could support a
great many useful queries, and you could encapsulate these in views
to make them easier to use.
I have amongs other two tables:
felevek_kezdetei_1_8 and
felev1_vege_tan_nap_1_8

iskolanaptar_201213=# set search_path to félévek_negyedévek;
SET

The first table contains the ordinal number of the semester (1 or 2) and
the start dates of the same:

iskolanaptar_201213=# select * from felevek_kezdetei_1_8;
felev1v2 | datum
----------+------------
1 | 2012-09-03
2 | 2013-01-15
(2 rows)

The second table contains the end date of the first semester and the
number of the days in this semester:

iskolanaptar_201213=# select * from felev1_vege_tan_nap_1_8;
datum | ennyi_tan_nap
------------+---------------
2012-12-21 | 78
(1 row)

So I'm trying as a beginning to create the 'felev_1_napjai' view that
should display only the first and the end date of the first semester:

iskolanaptar_201213=# create or replace view felev_1_napjai as select
datum from felevek_kezdetei_1_8, felev1_vege_tan_nap_1_8 where
felevek_kezdetei_1_8.felev1v2 = '1';
ERROR: column reference "datum" is ambiguous
LINE 1: create or replace view felev_1_napjai as select datum from f
^
Quote:
Are you having some problem doing so? What have you tried? What
did you expect to happen? What happened instead?
As you can see above I get error message.

If I success in this I shall modify this view so so I get a view of
dates between the start and the end date of the first semester. I shall
to use the generate_series somehow, but sofar I have no success.

--
Regards from Pal



--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #7  
Old   
Kevin Grittner
 
Posts: n/a

Default Re: [NOVICE] To get a Table or View like a Calendar with dates - 08-15-2012 , 04:08 PM



Csanyi Pal <csanyipal (AT) gmail (DOT) com> wrote:

Quote:
The first table contains the ordinal number of the semester (1 or
2) and the start dates of the same:

iskolanaptar_201213=# select * from felevek_kezdetei_1_8;
felev1v2 | datum
----------+------------
1 | 2012-09-03
2 | 2013-01-15
(2 rows)

The second table contains the end date of the first semester and
the number of the days in this semester:

iskolanaptar_201213=# select * from felev1_vege_tan_nap_1_8;
datum | ennyi_tan_nap
------------+---------------
2012-12-21 | 78
(1 row)
I think you need to rethink the table structure. It's not
immediately obvious why you wouldn't include the date of the end of
the semester in the same table as the start date for the semester
and the semester identifying information. You might want to read up
on data normalization for relational databases. The usual way of
organizing something like semester information would be to have a
table with the columns which identify a semester (perhaps school
year and semester number) and all the data elements which require
both of those elements, and only those elements, to determine the
correct value. That would probably include start date and end date
for the semester. (Or if you can start development with 9.2 beta at
this point, it might be even better to use a date range instead of
the two dates.)

You'll be in much better shape if you organize your data that way.
If you review the literature, you want to shoot for "3rd normal
form" -- below that level things tend to be pretty messy; above that
can get pretty esoteric.

-Kevin


--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.