Sunday, 15 August 2010

postgresql - Query Only Specific Days of Month -


I'm not sure where to start this problem, I need to update the records Only the third Monday of Can I ask on every second or third Monday in postgrace, or want a little more essence for the ninth day every week?

I am looking for a great response with PostgreSQL. I have this kind of raw now:

 select_desire to select d (date_trunc ('week', timestamp '2015-02-01' + interval '13 days '), timestamp' 2015- 02-01 '+ Interval' 1 month-1 day ', interval' 14 days') d;  

I like to use a calendar table for queries like this.

In 2015 to select the third Monday of every month, I can query a calendar table like this.

  Select cal_date from calendar where year_of_date = 2015 and DAY_OF_WEEK = 'Mon' and day_of_week_ordinal = 3 orders by Cal_date;  
CalDet - 2015-01-19 2015-02-16 2015-03-16 2015-04-20 2015-05-18 2015-06-15 2015-07-20 2015 - 08-17 2015-09-21 2015-10-19 2015-11-16 2015-12-21

Code for creating a calendar table (How to make pgAdminIII create your script menu selection presents through.)

  table calendar (Cal_date not born on nULL, year_of_date integer not nULL, month_of_year integer not nULL, DAY_OF_MONTH integer not nULL, DAY_OF_WEEK character (3) nOT nULL, Din_of_veik_varnank No integer, zero, iso_year integer no, zero Somewhere, iso_week integer is zero, cal_quarter integer, contract Kailender_paki primary key (cal_date), Contrastilt cal_quarter_check Czech (cal_quarter = case when date_part ( 'month' :: text, Cal_date) & gt; = 1 :: double precision and date_part ( 'Month' :: text, cal_date) & lt; = 3 :: double exact THEN 1 WHEN date_part ('month': text, cal_date)> = 4 :: double precision and date_text ('month' :: text , Cal_date) and = 6 :: double exact then 2 WHEN date_part ('month': text, cal_date) & gt; = 7 :: Double exact and date_part ('month': text, cal_data) and lt; = 9 :: Double exact then 3 WHEN date_part ('month' :: text, cal_date) & gt; = 10 :: Double public relations ecision and date_part ('month' :: text, cal_date) & lt; = 12 :: double precision then 4 and zero :: int end), barrier cal_quarter_range check (cal_quarter & gt; = 1 and cal_quarter & lt; = 4), barrier calendar_check check (year_of_date :: double precision = date_part ( 'year ':: text, cal_date)), barrier calendar_check1 check (month_of_year :: double precision = date_part (' month ':: text, cal_date)), barrier calendar_check2 check (DAY_OF_MONTH:: Double precision = date_part (' day ':: text , cal_date)), barrier calendar_check3 check (DAY_OF_WEEK :: text = case when date_part ( 'Dow' :: text, cal_date) = 0 :: double precision then 'Sun': text wHEN date_part ( 'dow' :: text , Cal_date) = 1 :: double exact THEN 'Text' WHEN date_part ('dow': text, cal_date) = 3 :: double exact THEN ' Mercury ': text WHEN date_part (' dow ':: text, cal_date) = 4 :: double exact THEN' gurus ':: text WHEN date_part (' dow ':: text, cal_det) = 5 :: double precision then' Venus' :: text wHEN date_part ( 'Dow' :: text Kail_det) = 6 :: double precision THEN 'Saturn' :: text otherwise :: text end, contracts Kailender_chek 4 Czech (Din_of_waik_ardin = case when Din_of_mnthti = 1 and Din_of_mnth & Lt; = 7 then 1 WHEN day_off_moth & gt; = 8 more day_off_manths & lt; = 14 THEN 2 WHEN day_off_moth & gt; = 15 and day_of_month & lt; = 21 THEN 3 when DAY_OF_MONTH & gt; = 22 and DAY_OF_MONTH & lt; = 28 then the rest 4 5 end), the obstacle calendar_check5 check (iso_year :: double precision = date_part ('isoyear' :: text, cal_date)), obstruct calendar_check6 test (iso_week :: double exact = date_party ('week': text, CalDDET))) (OIDS = False);  

You also need GRANT and REVOKE situations - very few people should be allowed to change the content of this type of table, and

  • Create appropriate index statements.

  • No comments:

    Post a Comment