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 1l98aR-0004L0-CF for psycopg@arkaria.postgresql.org; Mon, 08 Feb 2021 15:36:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l98aP-0005Og-Pm for psycopg@arkaria.postgresql.org; Mon, 08 Feb 2021 15:36:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l98aP-0005OS-Ha for psycopg@lists.postgresql.org; Mon, 08 Feb 2021 15:36:25 +0000 Received: from campbell-lange.net ([178.79.140.51]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l98aI-0005Of-VT for psycopg@postgresql.org; Mon, 08 Feb 2021 15:36:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=campbell-lange.net; s=it; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ago2STv4pHXJq596Eo4deVCGwuBMC0+lvP8uHt0u2To=; b=DMnROjvbjYuhfx+yw13YU9YXw 3pYpoEGLZ0Vhpd5wyGyTupDHTR5F1zg6wwTEZC+xPZzRuSWOX0pmwylO32LkcRwqyCZhyWVcZ5VE8 D47DCEOF3SOAN6CoXwOydrH3LGWO4T8DKXcfnB9Eqh/WbKwnJRCmYX97AJ1+X8tg/CXuQ=; Received: from 162.164.198.146.dyn.plus.net ([146.198.164.162] helo=rory-t470s) by campbell-lange.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l98aG-0006Uh-WC; Mon, 08 Feb 2021 15:36:17 +0000 Received: from rory by rory-t470s with local (Exim 4.92) (envelope-from ) id 1l98aG-0001YU-KL; Mon, 08 Feb 2021 15:36:16 +0000 Date: Mon, 8 Feb 2021 15:36:16 +0000 From: Rory Campbell-Lange To: Daniele Varrazzo Cc: Denis Laxalde , psycopg@postgresql.org Subject: Re: Latest developments in psycopg3 Message-ID: <20210208153616.GA4021@campbell-lange.net> References: <4eb4e86a-c813-bb8f-ae93-4f1b9fd46b6b@dalibo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 08/02/21, Daniele Varrazzo (daniele.varrazzo@gmail.com) wrote: > > - There appears to be no card about dictcursor on the project board. > > What's the plan (and priority) for that (if any)? ... > In psycopg2 there are: > > - DictCursor (returns a hybrid object between a sequence and a dictionary) > - RealDictCursor (returns a straight subclass of a dictionary, so it's > not a legit dbapi cursor as it doesn't expose a sequence) > - NamedTupleCursor (what it says on the tin). > > Personally I use the NamedTupeCursor most often, as I prefer the dot > notation to access attribute. ... > 1) We can provide a feature to select the type of cursor that is not > much dissimilar from psycopg2 > 2) Do we need DictCursor/RealDictCursor? ISTM that one of the two > would be sufficient? Possibly an object inheriting from a Python dict > instead of emulating it so that e.g. json.dumps() > 3) Or, conversely, we could have a Row object providing both attribute > and getattr access, both as index and name: > > row.myattr > row["myattr"] > row[1] A comment on this point. We use NamedTupleCursor a great deal as our system domain is modelled largely in the database in plpgsql. The only issue we've had with using NamedTupleCursor is when someone uses a space in column heading (the space translates to a "_") or trips up and uses the same column name for two columns. We class both cases as a mistake. Instead of making the NamedTupleCursor the default, I imagine many people accessing "raw" sql from python would benefit from the third option, of permitting list, dict or getattr type access to values. This would, presumably, be backwards compatible with current usage which I imagine is typically list oriented. A major benefit of getattr type access is that interactive debugging in iPython allows dot expansion, so introspection of the the row's attributes is wonderfully easy. Regards Rory