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.92) (envelope-from ) id 1j9oDk-0005i0-OO for pgsql-general@arkaria.postgresql.org; Thu, 05 Mar 2020 10:59:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9oDj-0004Yk-6q for pgsql-general@arkaria.postgresql.org; Thu, 05 Mar 2020 10:59:15 +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 1j9oDi-0004Vj-P5 for pgsql-general@lists.postgresql.org; Thu, 05 Mar 2020 10:59:14 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j9oDg-0006Kp-1c for pgsql-general@lists.postgresql.org; Thu, 05 Mar 2020 10:59:13 +0000 Received: from panix5.panix.com (panix5.panix.com [166.84.1.5]) by mailbackend.panix.com (Postfix) with ESMTP id 48Y76Q3HdLz1gh2; Thu, 5 Mar 2020 05:59:10 -0500 (EST) Received: by panix5.panix.com (Postfix, from userid 17622) id 48Y76Q1lpzzfYm; Thu, 5 Mar 2020 05:59:10 -0500 (EST) Date: Thu, 5 Mar 2020 05:59:10 -0500 From: stan To: "David G. Johnston" Cc: pgsql-general@lists.postgresql.org Subject: Re: Determining the type of an obkect in plperl Message-ID: <20200305105910.GA2832@panix.com> References: <20200304232135.GA16468@panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Editor: gVim List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Mar 04, 2020 at 05:09:19PM -0700, David G. Johnston wrote: > On Wed, Mar 4, 2020 at 4:21 PM stan wrote: > > > Probably a bit off topic, but I suspect someone on this list knows how to > > do > > this. > > > > I am in the process of writing a plperl function. In this function I need > > to compare the data in the NEW versus OLD structures. I am writing this as > > a > > generic subroutine, so I am looping through and comparing the 2 to see what > > is different. Problem is, that I need to know whether to us n != or a ne > > comparison. > > > > how can I determine what the data type of the value element is? > > > > Not up to speed on Perl but you basically want everything to be done using > string equality - can't you just use "ne" everywhere and not worry about > comparing numbers using string comparison logic? Might want to disabled > warnings... > > That would have to be faster than executing a type_of function on every > single column. > > Then measure performance and decide whether a generic routine is performant > enough. If not you might try creating custom function dynamically using > the catalogs as input. Since I am just looking for differences, this may work. Obviously comparing numeric values as strings has issues. Presently I am getting some warnings, so I think I need to deal with the types. I already dealt with the columns that return NULL, these are undefined in the Perl hash, so I have to test for their existence before attempting the compare. -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin