Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFtuC-0000sk-VN for pgsql-general@arkaria.postgresql.org; Tue, 08 May 2018 04:07:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fFtuB-0007gp-I9 for pgsql-general@arkaria.postgresql.org; Tue, 08 May 2018 04:07:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFtu9-0007gg-UW for pgsql-general@lists.postgresql.org; Tue, 08 May 2018 04:07:11 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFtu0-0006IB-5I for pgsql-general@lists.postgresql.org; Tue, 08 May 2018 04:07:09 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 71618228C0; Tue, 8 May 2018 00:06:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 08 May 2018 00:06:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=8Hx1QLdGkZEiYT3f4Yp1UFIjxRlDM uQzS/Y61mmy9Kc=; b=i08MIFlrbn7RPAVhzLSdGxUneWl+AVUm7wmG/yBOvfiag lLtm3soB4eZM1e9QpK1zZjF98t35DE6wB45+EFXtJ+HN83r9VmE/bOpQSst/cutS yQ1p00XZLmHFyX/3Z8g29iqntp0Xfax8RDTtH7FExPYuXjUyIlgo7Il8BGfug99/ 0TjreUb5E5NP/OgF+X0ANX/WKK4KZUtTJGM1oTM+D7OnP5MrTtvCbuQ0rTsDAB0y Uzwyfm9POwqrhsPLRolN+nPTfp9qesh/4Yq+lYpQOy9sAkQDuLFaMHhfwq4MBVDb wkkqulpACT9zX7OxwFSwVH4PPwCmlmmVsTFmkhKfA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=8Hx1QL dGkZEiYT3f4Yp1UFIjxRlDMuQzS/Y61mmy9Kc=; b=LuiHYdXgUlRcW60racuMwX mzM8SqqRKeWimOP/ALLUtx9c2/tf2o6L9kGZ78XA8ohqJ0/N3FWkBlUF6FgieDHC xVokp2Sb2H/E2Ndpvu0IS0vPITsbxKxJ1GQaa4kyN3q4qG6wslnCj3OFWzANxsbG SXPwevpFtG2wiNve63HYsOLLUcDWPk9jPU1y78aTTn/AyYAt1Ioe3QiChrIXu34o QPXMxqKvsuLJ1yY/qoLQLO2g0D3i70BEtQSpI7yjzDvUDd/3Es0A9y8A6K6t1FUo Z2J6pHzWDz6wuI0Z2j8n8PePARLrpoxHXbEnkmUGU1z8olm7Dvgq+cTL4zlYc3EA == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id A90101025C; Tue, 8 May 2018 00:06:56 -0400 (EDT) Subject: Re: KeyError: self._index[x] To: "David G. Johnston" , tango ward Cc: "pgsql-general@lists.postgresql.org" References: From: Adrian Klaver Message-ID: <661c8f00-ba13-3806-b7bd-2f05159df9b4@aklaver.com> Date: Mon, 7 May 2018 21:06:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/07/2018 08:50 PM, David G. Johnston wrote: > On Monday, May 7, 2018, tango ward > wrote: > > > cur_t.execute(""" >                 SELECT TRANSLATE(snumber, ' ', '') >                 FROM sprofile """) > > # This will result in KeyError > for row in cur_t: > print row['snumber'] > > # This works fine > for row in cur_t: > print row[0] > > > So apparently when you execute your query the result has at least one > column but that column isn't named "snumber".  I'm sure there is a way > in Python to debug "row" and find out what names it does have.  Or maybe Python 3+ print(row) Python 2.7 print row > execute the query in something like psql and observe e column name there. > > That said, by default the name of columns whose values are derived by a > single function call should be the name of the function.  So > "translate", not "snumber" - the latter being consumed by the function. > You can as use "as " to give it a different fixed name and refer > to that. > > David J. -- Adrian Klaver adrian.klaver@aklaver.com