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 1kla16-00049Y-65 for psycopg@arkaria.postgresql.org; Sat, 05 Dec 2020 16:02:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kla14-0001CU-FZ for psycopg@arkaria.postgresql.org; Sat, 05 Dec 2020 16:02:34 +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 1kla14-0001CN-Af for psycopg@lists.postgresql.org; Sat, 05 Dec 2020 16:02:34 +0000 Received: from smtp94.iad3b.emailsrvr.com ([146.20.161.94]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kla0z-0001mb-W1 for psycopg@lists.postgresql.org; Sat, 05 Dec 2020 16:02:33 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp20.relay.iad3b.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 2DE37A00AC; Sat, 5 Dec 2020 11:02:27 -0500 (EST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.5\)) Subject: Re: Handling (None,) Query Results From: Christophe Pettus In-Reply-To: <5f75fbb2-6da2-60f3-5488-9013d1328361@datasundae.com> Date: Sat, 5 Dec 2020 08:02:25 -0800 Cc: psycopg@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <0609481B-8907-402E-B995-9C0DEC590B41@thebuild.com> References: <5f75fbb2-6da2-60f3-5488-9013d1328361@datasundae.com> To: Hagen Finley X-Mailer: Apple Mail (2.3445.9.5) X-Classification-ID: 53ddb1cd-9248-40fc-945e-9e1a38f891d0-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Dec 5, 2020, at 07:57, Hagen Finley wrote: > 1. (Decimal('450992.10'),) to a 450992.10? >=20 > 2. (None,) to 0.00? > Thanks for your thoughts on this question. For #2, you can do that directly in the query: SELECT COALESCE(SUM(revusd), 0) FROM sfdc where saccount =3D = 'Big Company' AND stage LIKE 'Win%'; For #1, you can write it more compactly, of course: commitd1 =3D int(cur.fetchone()[0]) Note that there's no such thing as an int with value 450992.10, because = that's not an integer. It will truncate it if you cast it to int, or = you can use other operations to round it the way you'd like do. As you probably know, it's returning a tuple because you are getting = back a row of one column, and a Decimal because (presumably) that's what = type revusd is in the database. -- -- Christophe Pettus xof@thebuild.com