Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o9nNv-0001T8-U1 for pgsql-general@arkaria.postgresql.org; Fri, 08 Jul 2022 12:47:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o9nNu-0007WM-Ir for pgsql-general@arkaria.postgresql.org; Fri, 08 Jul 2022 12:47:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o9nNu-0007WD-8U for pgsql-general@lists.postgresql.org; Fri, 08 Jul 2022 12:47:02 +0000 Received: from smtp.burggraben.net ([88.198.69.140]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o9nNp-0007Pm-CM for pgsql-general@lists.postgresql.org; Fri, 08 Jul 2022 12:47:01 +0000 Received: from elch.exwg.net (elch.exwg.net [IPv6:2001:470:7120:1:127b:44ff:fe4f:148d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "elch.exwg.net", Issuer "R3" (not verified)) by smtp.burggraben.net (Postfix) with ESMTPS id AF2AFC00316; Fri, 8 Jul 2022 14:46:54 +0200 (CEST) Received: by elch.exwg.net (Postfix, from userid 1000) id 1662D3AB07; Fri, 8 Jul 2022 14:46:54 +0200 (CEST) Date: Fri, 8 Jul 2022 14:46:54 +0200 From: Christoph Moench-Tegeder To: Rajesh S Cc: pgsql-general@lists.postgresql.org Subject: Re: - operator overloading not giving expected result Message-ID: References: <7f97243d-db62-199a-8412-5637963d117e@fincuro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7f97243d-db62-199a-8412-5637963d117e@fincuro.com> User-Agent: Mutt/2.2.6 (2022-06-05) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ## Rajesh S (rajesh.s@fincuro.com): > We are migrating our database from Oracle to Postgresql.  In oracle we > have used this syntax "SELECT ('1999-12-30'::DATE) - > ('1999-12-11'::DATE)" to get difference between two dates as a integer > output (ex: 19).  But in Postgres the same query returns result as "19 > days". There's something fishy going on, as (date) - (date) returns integer since a very long time (even the version 8.0 docs have that). On the other hand, (timestamp) - (timestamp) gives an interval, so first make sure you really got the data types right. > CREATE OR REPLACE FUNCTION public.dt_minus_dt( >     dt1 timestamp without time zone, >     dt2 timestamp without time zone) See? There's TIMESTAMP, not DATE. >     LANGUAGE 'edbspl' Is this really PostgreSQL or is it that fork - and if it's the fork, does it behave the same way as stock PostgreSQL does? (I would be surprised if that deviates in this place, but...). >     SELECT DATE_PART('day', dt1::timestamp - dt2::timestamp)::integer And TIMESTAMP again. Regards, Christoph -- Spare Space