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 1l99ZH-0006Yg-KG for psycopg@arkaria.postgresql.org; Mon, 08 Feb 2021 16:39:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l99ZG-0005GO-4g for psycopg@arkaria.postgresql.org; Mon, 08 Feb 2021 16:39:18 +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 1l99ZE-0005GH-PH for psycopg@lists.postgresql.org; Mon, 08 Feb 2021 16:39:17 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l99ZB-0004bX-Lv for psycopg@postgresql.org; Mon, 08 Feb 2021 16:39:15 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 6B0AABC0; Mon, 8 Feb 2021 11:39:11 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 08 Feb 2021 11:39:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=D jDaTLxtkKxy9USCxcOm6JvmYSQQ26NEfFTpLR0PJU0=; b=D81PWVVCEeS+AIe5L mDMJiMCtEU7g5eCSFiJbQlGShhej4QkrhRzbVRHQzG/oBgs7zZDNYzLpCZpCI4gL 4lKnR6niEVdIjx5PlmLULvzcih8ocA1mL7xlLbpdLwZ8Kw8t9LiI8v47VH70lBdb bQyJm9fGplYgokGPctqArMEVNviMwmH5uV2UowlS70s/CsOnownM9uV4gE1qFaqP 3fOyY0ztNnYO4D3PMYFTFJxKK87DquCvmFd4MxrU0pNl0U9UdPWqWXGXVGT4E8gr qHU2I7ZOGXoD3gsGkQ+4FygCerxjt1hKPia57xSaltuDIMSmMpdLk2bVQ7wu2me7 XNdSg== 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=DjDaTLxtkKxy9USCxcOm6JvmYSQQ26NEfFTpLR0PJ U0=; b=wdCvA4Ed7HxIbQYGW5rVjyeFYg8jO4b38WS2gQQjGFUZsoSqs2gKTHWtg 9AR65rR5DbDjs8TNYkKIuq3uLD8KMuPzmjVbArV4UI5TkJRiJ3Evin5NsPYQ5MX3 Elv57aDSyqJyCWfV0naBgFPgNX24wrs/RCEjwX97E/DA+mLWBOjUZv6cf5pvbZ0p ud6Eh0oDF6o4ZO8lWFZwF2nVNfX3Hty2QYHfmBxIXGBxl3FPW3Iu2DcBtE7LOvSt PmuppTK6Gl73EIQ5smDWodr9RfuPatAaJ8lwOKK8MdqwrSDuDHv+cbHtVNW4tZJN Ja6vSp6Af8hQgr0G0FJWqYx9YtT7g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrheefgdeludcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepteejvdetffejuedvleeifeefheeutdfhgfdvhffhhfek vdduveegvdejudefgfevnecukfhppeeljedruddufedrvddujedrvdejnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.4] (97-113-217-27.tukw.qwest.net [97.113.217.27]) by mail.messagingengine.com (Postfix) with ESMTPA id 3AC1B240062; Mon, 8 Feb 2021 11:39:09 -0500 (EST) Subject: Re: Latest developments in psycopg3 To: Daniele Varrazzo , Denis Laxalde Cc: psycopg@postgresql.org References: <4eb4e86a-c813-bb8f-ae93-4f1b9fd46b6b@dalibo.com> From: Adrian Klaver Message-ID: <34c98d4f-b26a-bc79-09e4-6567c38e92fa@aklaver.com> Date: Mon, 8 Feb 2021 08:39:08 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/8/21 4:16 AM, Daniele Varrazzo wrote: > Hello Denis, > > In short: yes, I would like to provide alternative record factories. > We can review if the best way is to create cursor subclasses > out-of-the-box or mixins. 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. Named tuples also have a _dict() method > when a dict is needed. If psycopg3 was only my pet project, I would > personally have NamedTuples as the default and only thing supported... > But that's hardly the case. > > 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() RealDictCursor is what I use primarily as it plays well with json.*. I have used NamedTupleCursor for those things that play better with dot notation. I very rarely use DictCursor anymore as it's dual nature seemed to get in the way more then it helped. > 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] > > 4) There are reports of the *DictCursor being slow: the objects in > psycopg2 have hardly been profiled. I would look well at the > performance of the objects created. > > -- Daniele > > -- Adrian Klaver adrian.klaver@aklaver.com