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 1kc5rH-0003Kk-4B for psycopg@arkaria.postgresql.org; Mon, 09 Nov 2020 12:01:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kc5rG-0004mO-2j for psycopg@arkaria.postgresql.org; Mon, 09 Nov 2020 12:01:14 +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 1kc5rF-0004mH-RN for psycopg@lists.postgresql.org; Mon, 09 Nov 2020 12:01:13 +0000 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kc5rB-0001GE-6W for psycopg@lists.postgresql.org; Mon, 09 Nov 2020 12:01:13 +0000 Received: by mail-lj1-x236.google.com with SMTP id 23so9943337ljv.7 for ; Mon, 09 Nov 2020 04:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=F6BI2g8C3gyAwalellPX1zJ/Vavc/fm7WOp8pAtnJ6Y=; b=elyR+GeyeB7iLUQf26pa9gy8xLb2x2z5Km15HC/FP6OByKqH1MV6nyxfubCx/3Bn0L T2s633zpaARaBQhB/rk2GCgwQbeYMsEpfdYKxhbXLgEviv75ASseRkeYyo9RZIelvm4K Y/XV5g7mPON3pbacYXu7mgyyjfGvTi814uKzGkoIm4TXUrkEgHzXQsJzxPwoNIaKNpql xIsMDhKLjaBhKaBsnaCBt0VRn7WImaiKQL2VSATIxHxPWs0fWr6Ck1Y2ZE8Osdm73GJX 0c6VoEO0NMzJ8PRi9g5SBh8tN6pByrxqurZIvJLGUaqOGYuHPGuMgow0rPOVPVhGknkC TxjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=F6BI2g8C3gyAwalellPX1zJ/Vavc/fm7WOp8pAtnJ6Y=; b=ZRbIiSolcAlcCKnZ3ku9n7WFrQbQ2711cwsw/e5WEioJHb1Y4bFUwqkxnPqW3xITt9 l/S2ejCM9FsCVK7VFsoMTHfDoq6LsPmC2toTJP5TW9ayHHx2pQi2wR12PZx2pEGes8hs /aP1xZgo6ysh4m+1yuYfX+cAgG23zdBx8MzhEa96Ymth6Vwp7Bse/EkHAww9njOa/EyZ YH7jFu77q5TiC8GKHQooN5lFTdSQxDfZ3hxReUq4Uh08qGVCrQ+xWXCun2JzBf+Q3DiV nuG4qIv4Mtaq68lUANfttp+HawI6h5yc67hHrcLVfigbc8fxrXnKr7vWlokUEO1JSmxE seKw== X-Gm-Message-State: AOAM531GGnW+3AU8bbnhsG/IiM2c5W2HI/kZqHk1oKEt408yUEIiSXCo gPs9Thy2VQl5fUxplYJYYCeJBfV7KAZ3ecNiig4kFROHprkVUw== X-Google-Smtp-Source: ABdhPJwMlOovOwQ66ZkIAla23pEA1YZCEZmUTEAvg2DN0MCNoU2kAU4IScomCbG5wnO6oBpyTWqMGzmCMYRiVZu1AfI= X-Received: by 2002:a2e:9a0c:: with SMTP id o12mr5694123lji.104.1604923267386; Mon, 09 Nov 2020 04:01:07 -0800 (PST) MIME-Version: 1.0 References: <2b9859f0-0964-2baa-b6bc-13f975ae0f67@aklaver.com> <88fb7a7e-a182-a816-c1a7-8a1f54b65215@aklaver.com> <4830fb8d-fa57-e0f8-0e4f-a96ed040dede@dndg.it> In-Reply-To: <4830fb8d-fa57-e0f8-0e4f-a96ed040dede@dndg.it> From: Daniele Varrazzo Date: Mon, 9 Nov 2020 12:00:55 +0000 Message-ID: Subject: Re: psycopg3 and adaptation choices To: Federico Di Gregorio Cc: psycopg@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 9 Nov 2020 at 06:57, Federico Di Gregorio wrote: > In your example I'd just go for int8 (the largest possible int in > PostgreSQL). Decimal would probably be better (largest range) but it is > not what the majority of people would expect. The problem with int8 is that it fails in all the cases where decimal fails, while not allowing to pass values larger than 64 bits: piro=# select '[10,20,30]'::jsonb -> 1::int8; ERROR: operator does not exist: jsonb -> bigint LINE 1: select '[10,20,30]'::jsonb -> 1::int8; ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. You are right though that, in terms of round-trippig, decimal might be unexpected too: >>> cur.execute("select %s", [10]).fetchone()[0] Decimal('10') So uhm... that's a +1 for that option too :D > IMHO, oid is a bad idea > because it has a very specific semantic and the error messages generated > by PostgreSQL will be more confusing. I'm not sure I understand this. At the moment, the oids are something that don't really surface to the end-users, who are not required to use them explicitly and shouldn't be seen in the error messages. For instance the query above might results in a call: >>> from psycopg3.oids import builtins >>> builtins["numeric"].oid 1700 >>> res = conn.pgconn.exec_params(b"select '[]'::jsonb -> $1", [b"1"], [1700]) >>> res.status >>> print(res.error_message.decode("utf8")) ERROR: operator does not exist: jsonb -> numeric LINE 1: select '[]'::jsonb -> $1 ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. So the oid is only used internally, in the mapping python type -> exec_params() types array, the 1700 shouldn't surface anywhere. Maybe I'm misunderstanding your concern: can you tell me better? -- Daniele