Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 6354B9FB7E4; Thu, 5 Jul 2007 17:50:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 74426-06; Thu, 5 Jul 2007 17:49:54 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sr06-03.mta.terra.com.br (sr06-03.mta.terra.com.br [200.154.152.72]) by postgresql.org (Postfix) with ESMTP id C4BEB9FB8A3; Thu, 5 Jul 2007 17:49:55 -0300 (ADT) Received: from taragoro.hst.terra.com.br (taragoro.hst.terra.com.br [200.176.10.9]) by burta.hst.terra.com.br (Postfix) with ESMTP id 586343A6807F; Thu, 5 Jul 2007 17:49:53 -0300 (BRT) X-Terra-Karma: -2% X-Terra-Hash: 2694b078e3a3e52a6a14900051b73ac7 Received-SPF: pass (taragoro.hst.terra.com.br: domain of terra.com.br designates 200.176.10.9 as permitted sender) client-ip=200.176.10.9; envelope-from=ranieri.oliveira@terra.com.br; helo=[172.16.2.72]; Received: from [172.16.2.72] (200-162-219-207.corp.ajato.com.br [200.162.219.207]) (authenticated user ranieri.oliveira) by taragoro.hst.terra.com.br (Postfix) with ESMTP id 7D8685016F; Thu, 5 Jul 2007 17:49:52 -0300 (BRT) Message-ID: <468D5959.7090404@terra.com.br> Date: Thu, 05 Jul 2007 17:49:29 -0300 From: Ranieri Mazili User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: pgsql-general@postgresql.org, pgsql-sql@postgresql.org Subject: Re: Working with dates References: <468D3FD8.7070807@terra.com.br> In-Reply-To: <468D3FD8.7070807@terra.com.br> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.436 tagged_above=0 required=5 tests=AWL=1.176, BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 200707/215 X-Sequence-Number: 116816 -------- Original Message -------- Subject: [GENERAL] Working with dates From: Ranieri Mazili To: pgsql-general@postgresql.org, pgsql-sql@postgresql.org Date: 5/7/2007 16:00 > Hello, > > I need to do the following select: > > Number of days of month - weekends - holydays > > So this query will return the number of days that people can work > > Look that I have the holydays in one table, it's bellow: > > CREATE TABLE holidays > ( > id_holidays serial NOT NULL, > dt_holiday date, > holiday_description character varying(60), > input_date timestamp without time zone NOT NULL, > CONSTRAINT holidays_pkey PRIMARY KEY (id_holidays) > ) > > I have no idea of how do it > > If someone could help, I would appreciate. > > Thanks > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > > I can. select count(A.data) from (select (date_trunc('month',(select production_date from production order by production_date desc limit 1)::date)::date + x * '1 day'::interval)::date as data from generate_series(0,31) x) A where extract(month from A.data) = extract(month from (select production_date from production order by production_date desc limit 1)::date ) and extract(dow from A.data) <> 0 and extract(dow from A.data) <> 6 and A.data not in (select dt_holiday from holidays)