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 1kbrPN-0002lH-HY for psycopg@arkaria.postgresql.org; Sun, 08 Nov 2020 20:35:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kbrPL-0004gT-6b for psycopg@arkaria.postgresql.org; Sun, 08 Nov 2020 20:35:27 +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 1kbrPJ-0004gK-Qm for psycopg@lists.postgresql.org; Sun, 08 Nov 2020 20:35:27 +0000 Received: from [64.147.123.20] (helo=wout4-smtp.messagingengine.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kbrPD-0005Ap-2I for psycopg@postgresql.org; Sun, 08 Nov 2020 20:35:24 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 4B243A91; Sun, 8 Nov 2020 15:35:07 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sun, 08 Nov 2020 15:35:07 -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=fm1; bh=5 vh6vwj33S/rjH5vZNXQYqZkge6WYahiXj0qTWnTQXs=; b=SBf+FgqmefvGoxjjN M3vpUdb7YC4Du7ZNakyWKzKLNMP1Kil3A75tEZ57UQKVQBCsz02bnAn2ET2txsTM cGgT+905+RMxiT3G1W84mLuCIRJErlREtTXoSrBzYC9flcq8HQvt2yyFPD/M/eqv VHZKtbszun4Cj7npMDjQR4ufgAoI02XvjzZlW5MOQakFPGay2d7KuiAQvJEkmiyg vc7AJI6mE0wTZXG4O7OcWO8R2SooqtkCI9MBxf99cAm3Y0UNQbIsaNPc2hwmRP7j 3fH35l/YZEkMNu6foQeefeWUhulGC296iU0oRNrnkwaQkzBaDpvc4FQnt5eHDvtM sIgkw== 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=fm1; bh=5vh6vwj33S/rjH5vZNXQYqZkge6WYahiXj0qTWnTQ Xs=; b=XHwkjc4jCmR7D2frlZvhuyYG7GHi8atixMidkVrJuQPyy0ChSUcJceDKS izhbMGW1x+m4EzO5SV6NDpJfHcljh8oZOIlMQcdjva5WQtYKuKUS0S5TAuyuxVVk Grm7Lrx3iYfYWlbfhVTINGFxyf00TF7de14SYaDQf/hLkL7SQ+DwA2mc1Z7ozTYa hZAKsH1e0Rzmxv50AT4QhIY9nZQB/49M79fcY0fcIcpfqKJTByqrwWKW0CAmiIgt ZbiAHT9GefvBocgHfMPQ9Ec2fmtMZZhR6mxCkyQJMJlfVQQr4C1mSVylsMjX+MCv RezZ7flw8SMQ07mWLW8yfoF43JDZA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddufedgudegtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepteejvdetffejuedvleeifeefheeutdfhgfdvhffh hfekvdduveegvdejudefgfevnecukfhppeejhedrudejvddrudelrddufeelnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.4] (75-172-19-139.tukw.qwest.net [75.172.19.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 4493C3063082; Sun, 8 Nov 2020 15:35:06 -0500 (EST) Subject: Re: psycopg3 and adaptation choices To: Daniele Varrazzo Cc: psycopg@postgresql.org References: <2b9859f0-0964-2baa-b6bc-13f975ae0f67@aklaver.com> From: Adrian Klaver Message-ID: <88fb7a7e-a182-a816-c1a7-8a1f54b65215@aklaver.com> Date: Sun, 8 Nov 2020 12:35:05 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.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 X-Host-Lookup-Failed: Reverse DNS lookup failed for 64.147.123.20 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/8/20 11:16 AM, Daniele Varrazzo wrote: > On Sun, 8 Nov 2020 at 18:43, Adrian Klaver wrote: > >> If I'm following correctly in psycopg2 the adapter does type adaption on >> the client side and passes that to server with oid for processing. In >> psycopg3 you are proposing to let the server do more of the type >> adaption and to that end you are looking for lowest common denominator >> type to pass to server and then let it do the final casting. Is that >> about right or am I way off base? > > No, not really. In psycopg2 we compose a query entirely client-side, > and we pass it to the server with no oid indication, only as a big > literal, like it was typed all in psql. In the example of > `cursor.execute("select %s, %s", ["hello", 10])`, the server receives > a literal `select 'hello', 10` and has no idea that there were two > parameters. Alright I understand now. More below. > > In psycopg3 the idea is to use a more advanced protocol, which > separates query and parameters. It brings several benefits: can use > prepared statements (send a query once, several parameters later), > passing large data doesn't bloat the parser (the params don't hit the > lexer/parser), can use binary format (useful to pass large binary > blobs without escaping them in a textual form), the format of the data > is more homogeneous (no need to quoting), so we can use Python objects > in COPY instead of limiting the interface for the copy functions to > file-like objects only. > > Both in psycopg2 and 3 there is an adaptation from Python types to > Postgres string representation. In pg2 there is additional quoting, > because apart from numbers and bools you need to quote a literal > string to merge it to the query and make it syntactically valid. So the issue in the psycopg3 protocol is making the parameters that are passed in separately match up correctly in type to what the server is expecting(or can cast implicitly)? > > -- Daniele > -- Adrian Klaver adrian.klaver@aklaver.com