Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2dEE-0002e3-C3 for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Oct 2017 13:08:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e2dED-0007SR-Uw for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Oct 2017 13:08:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e2aIp-0002D3-8I for pgsql-bugs@postgresql.org; Thu, 12 Oct 2017 10:01:19 +0000 Received: from forward5o.cmail.yandex.net ([37.9.109.249]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e2aIh-0006zh-JD for pgsql-bugs@postgresql.org; Thu, 12 Oct 2017 10:01:18 +0000 Received: from mxback13j.mail.yandex.net (mxback13j.mail.yandex.net [IPv6:2a02:6b8:0:1619::88]) by forward5o.cmail.yandex.net (Yandex) with ESMTP id A4EF7216BE; Thu, 12 Oct 2017 13:01:07 +0300 (MSK) Received: from web37j.yandex.ru (web37j.yandex.ru [2a02:6b8:0:1619::337]) by mxback13j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id JLckdCVYnL-16pugcL0; Thu, 12 Oct 2017 13:01:06 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1507802467; bh=BU86x9GDx3j3+0d1mQa4qxClvSBGlnE8kV1OmIP+pV8=; h=From:To:Cc:In-Reply-To:References:Subject:Message-Id:Date; b=gVKUD4DlDNyjsSCb/vSRWItBYUe9x/eUXnY3IHDkypEzQAn22BkUMzqxNryzDlxid kCckxkREdW+dMX7g5Pbx+TcrLSp2nlOIu51v76CdyTuIjb/af69ACpzjkzdsTbnLIz enyxW8ltd8ezL/LOnHnMMUFVE46//Rd8gShsAN+g= Authentication-Results: mxback13j.mail.yandex.net; dkim=pass header.i=@yandex.ru Received: by web37j.yandex.ru with HTTP; Thu, 12 Oct 2017 13:01:06 +0300 From: KES Envelope-From: kes-kes@yandex.com To: Arthur Zakirov Cc: "pgsql-bugs@postgresql.org" In-Reply-To: <20171012091542.GA8159@zakirov.localdomain> References: <20171011103512.1452.9244@wrigleys.postgresql.org> <20171012091542.GA8159@zakirov.localdomain> Subject: Re: BUG #14850: Implement optinal additinal parameter for 'justify' date/time function MIME-Version: 1.0 Message-Id: <207501507802466@web37j.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Thu, 12 Oct 2017 13:01:06 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org No. Your example work only for those values. Try this: SELECT extract( month from justify_days( timestamp '2016-02-29' -timestamp '2016-01-31') ); date_part ----------- 0 (1 row) select extract( month from justify_days( timestamp '2016-02-29' -timestamp '2016-01-31'), timestamp '2016-01-31' ); date_part ----------- 1 (1 row) 12.10.2017, 12:15, "Arthur Zakirov" : > On Wed, Oct 11, 2017 at 10:35:12AM +0000, kes-kes@yandex.ru wrote: >>  >Adjust interval so 30-day time periods are represented as months >> >>  https://www.postgresql.org/docs/9.6/static/functions-datetime.html > > Yes, it seems that it is because timestamp operations return '29 days': > > =# SELECT timestamp '2016-01-31' +interval '1 month' -timestamp '2016-01-31'; >  ?column? > ---------- >  29 days > > You can also try the following, maybe it is appropriate for you: > > =# SELECT timestamp '2016-01-31' -timestamp '2016-01-31' +interval '1 month'; >  ?column? > ---------- >  1 mon > > =# SELECT extract( month from justify_days( timestamp '2016-01-31' > -timestamp '2016-01-31' +interval '1 month') ); >  date_part > ----------- >          1 > > -- > Arthur Zakirov > Postgres Professional: http://www.postgrespro.com > Russian Postgres Company -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs