Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJJgT-0006cR-Vq for pgsql-general@arkaria.postgresql.org; Sat, 12 Oct 2019 15:51:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iJJfU-00077t-RC for pgsql-general@arkaria.postgresql.org; Sat, 12 Oct 2019 15:50:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJJfU-00077a-Bp for pgsql-general@lists.postgresql.org; Sat, 12 Oct 2019 15:50:56 +0000 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iJJfN-0000tT-G5 for pgsql-general@lists.postgresql.org; Sat, 12 Oct 2019 15:50:55 +0000 Received: by mail-yw1-xc41.google.com with SMTP id x64so4609946ywg.3 for ; Sat, 12 Oct 2019 08:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=MFWioU2JPxJ1T44K6zz0jrQWrgjjyTeD2qtsV5X0a14=; b=Pnwa9iaUU59XfVOZYRUZdGsYqH667KA8EsjsFuwSMGdxZtoGx83nJzZTwygW9Ls7cr HTNGzWX8WT+zvy8GKLiBf2c6Ozzl+1yRervrWq08fc3i9tc4FkXE2HRblmPx1pjhOeoS 6sj96HZsoh3SI0oaemEeTkGqTuUGzDF+MfS16Ahxm0t5LvG226w9lZycTBb1YqBMsOZj OYCNZ4pmxHLZKia8y/NmHune8llcfvtlyb64YZXma+A8I/mz+riVEM6vxNcAX5ezZG/J +xl5t+OERn/iiX7nVZ2NjkIPNXWV+KxQuAllcuPSdpjmp339CCzd3JTV+gRwMF0GdCPu 1f6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=MFWioU2JPxJ1T44K6zz0jrQWrgjjyTeD2qtsV5X0a14=; b=rO0gmdnh5R0HILbsfYLo0UW1aH2hVDPwbwASDRi4zjodoKujO1Il56h/HrttIaZe15 r4/mPcFW5KXQuNH5/zpSphphY4e9JeaG2FVhj2g/XwNQvhz4wH+oh2JeYSmXQuTmYxdE Ilaezq8gWwDYElzRaYsy4T+mHMjsOuP2+3xKDpBBZQbtNZLzO63fDijFzbgKjT7Ln9+J OC8VJi5bbVmedzndQ4HHvGAelMXshTQgc+0vEUXOn5pmqjEKjASXqLKqWGOHzgjguzB4 g7UbJgvX+dnAFVTPPO9zPgmtTp9Ha6X9jaIj/iMY3RKvTvFGiaW9YI5EqvBQEdewhONm cMVw== X-Gm-Message-State: APjAAAWYx6AqHt/tyLb/7t5kRqD3392jCtwnmjbLhuak4BAaFAbJD5Qk 7BdlptyGb3UaZZP9vA0TdZ1YdRqMj34= X-Google-Smtp-Source: APXvYqx5/drFhHSsjpWjVn7UCO8Cgl53Mdb4eddb+GMo+y8Sh25g2ToZaANypEE5bh6HqYJUf/gXDA== X-Received: by 2002:a81:6389:: with SMTP id x131mr6688332ywb.167.1570895448354; Sat, 12 Oct 2019 08:50:48 -0700 (PDT) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id v8sm3116934ywg.91.2019.10.12.08.50.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Oct 2019 08:50:47 -0700 (PDT) Subject: Re: day interval To: pgsql-general@lists.postgresql.org References: <8736fyxa2a.fsf@news-spur.riddles.org.uk> From: Ron Message-ID: Date: Sat, 12 Oct 2019 10:50:46 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------770C62A5F193DED6DED9396B" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------770C62A5F193DED6DED9396B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Date subtraction returns the integer data type; timestamp subtraction returns the interval datatype. postgres@haggis:~$ psql test psql (9.6.15) Type "help" for help. test=# select date('20191001') - date('20190923');  ?column? ----------         8 (1 row) test=# select date('2019-10-01') - date('2019-09-23');  ?column? ----------         8 (1 row) test=# select cast('2019-10-01 00:00:00.000' as timestamp) - cast('2019-09-23 00:00:00.000' as timestamp);  ?column? ----------  8 days (1 row) test=# select pg_typeof(cast('2019-10-01 00:00:00.000' as timestamp) - cast('2019-09-23 00:00:00.000' as timestamp));  pg_typeof ----------- *interval* (1 row) On 10/12/19 10:37 AM, Abraham, Danny wrote: > Thanks Andrew. > > My code fails since the expression (In a PG/PG SQL function) which assumes integer result > Now produces the string '8 day'; > > This has been working for years on all PG community servers. > > This happens on an EDB PG 9.6.3. > > I know the fix, but I need the ability to create the bug in my server, and I do not know how. > > Thanks > > Danny > > > -----Original Message----- > From: Andrew Gierth > Sent: Saturday, October 12, 2019 6:26 PM > To: Abraham, Danny > Cc: pgsql-general@postgresql.org > Subject: [EXTERNAL] Re: day interval > >>>>>> "Abraham" == Abraham, Danny writes: > Abraham> Hi > Abraham> A question on day interval > > Abraham> select date('20191001') - date('20190923'); > > Abraham> Will provide sometimes '8' - an integer , but sometimes '8 Abraham> day' - a string > > No, it'll always return an integer. You will only get an interval result if you subtract timestamps rather than dates, for example if one of the operands is actually an expression returning a timestamp. > > Give an example of an actual expression you used that returned an interval instead, and we may be able to tell you how to fix it. > > -- > Andrew (irc:RhodiumToad) > > -- Angular momentum makes the world go 'round. --------------770C62A5F193DED6DED9396B Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Date subtraction returns the integer data type; timestamp subtraction returns the interval datatype.

postgres@haggis:~$ psql test
psql (9.6.15)
Type "help" for help.

test=# select date('20191001') - date('20190923');
 ?column?
----------
        8
(1 row)

test=# select date('2019-10-01') - date('2019-09-23');
 ?column?
----------
        8
(1 row)

test=# select cast('2019-10-01 00:00:00.000' as timestamp) - cast('2019-09-23 00:00:00.000' as timestamp);
 ?column?
----------
 8 days
(1 row)

test=# select pg_typeof(cast('2019-10-01 00:00:00.000' as timestamp) - cast('2019-09-23 00:00:00.000' as timestamp));
 pg_typeof
-----------
 interval
(1 row)



On 10/12/19 10:37 AM, Abraham, Danny wrote:
Thanks Andrew.

My code fails since the expression (In a PG/PG SQL function) which assumes integer result
Now produces the string '8 day';

This has been working for years on all PG community servers.

This happens on an EDB PG 9.6.3.

I know the fix, but I need the ability to create the bug in my server, and I do not know how.

Thanks

Danny


-----Original Message-----
From: Andrew Gierth <andrew@tao11.riddles.org.uk> 
Sent: Saturday, October 12, 2019 6:26 PM
To: Abraham, Danny <danny_abraham@bmc.com>
Cc: pgsql-general@postgresql.org
Subject: [EXTERNAL] Re: day interval

"Abraham" == Abraham, Danny <danny_abraham@bmc.com> writes:
 Abraham> Hi
 Abraham> A question on day interval

 Abraham> select date('20191001') - date('20190923');

 Abraham> Will provide sometimes '8' - an integer , but sometimes '8  Abraham> day' - a string

No, it'll always return an integer. You will only get an interval result if you subtract timestamps rather than dates, for example if one of the operands is actually an expression returning a timestamp.

Give an example of an actual expression you used that returned an interval instead, and we may be able to tell you how to fix it.

--
Andrew (irc:RhodiumToad)



--
Angular momentum makes the world go 'round.
--------------770C62A5F193DED6DED9396B--