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 1ki04F-00078c-Jt for psycopg@arkaria.postgresql.org; Wed, 25 Nov 2020 19:03:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ki04E-00078M-JZ for psycopg@arkaria.postgresql.org; Wed, 25 Nov 2020 19:03:02 +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 1ki04E-00078F-CK for psycopg@lists.postgresql.org; Wed, 25 Nov 2020 19:03:02 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ki047-00016X-OK for psycopg@postgresql.org; Wed, 25 Nov 2020 19:03:02 +0000 Received: by mail-lf1-x131.google.com with SMTP id v14so4641886lfo.3 for ; Wed, 25 Nov 2020 11:02:55 -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=wPSbe36igFzFFFYuRN4o0os6garVp3YqEln2+HaRISU=; b=l+/0Joa7BRXz4dZao1gzpPsKU0gzesSyjNR2fZsZboG32Tw+rJnVWG9DKUnvGXasIL AKiuGOziOcHpuC4WdV/C5gQlm5B84iEo5+xr4QAAZd0PtDRXy1dOz2ai+OVyGO+33SLZ 5e0SR5lY8GONf340PyZmcedv8JQm3Fza90Gmn4ZOyQLxXTFQwSJNBMwm11mPSjLOIRf+ FAO1NueXN/w9v8Tyj87LzIE90+oLf958uif28Ol8tIqi2wRqKeJOH/VoqDg9TVtDEutF VJwfESJYNV8+Uh8L5USWW7HYK3Yy2Bnr2lXpwdODQQaPOhnNnPz0/tt8SEEi3UKxx90a wrEQ== 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=wPSbe36igFzFFFYuRN4o0os6garVp3YqEln2+HaRISU=; b=T0AvgEwphqJV2pB3t18kv0sAtuglnlOB02gGoze3qcjGZ6VFWyXy1DSCe/4FFDFufQ w4P2vjDBhOJpwzRQao3+wumlT4v66Dn5Ce14j+vdKGLkJN8lzyy4qfPt9Eimjpfg1hxu tvPaC10yv7PBnm5xwYXjNqYS5o/4Qtzcjh7Z7Z2qIA0fHOK/v/xnKb5tcKRVfDTl5IH2 HgcaYbjl9qqR4b06FXkafOpoTphEzRSvEJWcxZUXzd8ZlVHoYkxVoigjAzn6z9ydJ+02 ciWsg+lhj28J1Pv0WdQdfYZDa819eMuiC1GMab+6kranUxCGvbhhLvm93zgvZtKO433L kldg== X-Gm-Message-State: AOAM530t+m0N/TquGhglXCej0PIJ9fBXxGJ4VBENEl6wn5q7KciGqXF7 uzfWfc10ocXGKedpAPUGJFhoPg/sIRKxXsUisMgAUdS2blhQSQ== X-Google-Smtp-Source: ABdhPJx0UKaU2wleprvgv4tyPkB/eQYhEzjJ7lbr10BRmjncU5oqjkAELfXA6M3PweW2V8yriZLcg8pg7vEeK88SnmY= X-Received: by 2002:a19:6416:: with SMTP id y22mr101506lfb.555.1606330974148; Wed, 25 Nov 2020 11:02:54 -0800 (PST) MIME-Version: 1.0 References: <7ec5da30-9d28-2bab-7eaa-7038711a99f0@soft-com.es> <9d1b2ad5-37a3-ebce-a622-24c6a1f5e1b4@soft-com.es> In-Reply-To: <9d1b2ad5-37a3-ebce-a622-24c6a1f5e1b4@soft-com.es> From: Daniele Varrazzo Date: Wed, 25 Nov 2020 19:02:42 +0000 Message-ID: Subject: Re: Adaptation in psycopg3 To: listas Cc: psycopg@postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 25 Nov 2020 at 18:00, listas wrote: > Thank for your replies, I will use "=any(params list)" in psycopg3 No problem. But if it was not clear, this is something that works already in psycopg2 too: it could be useful if you want to port code later. > The second question is: if psycopg3 is going to do the automatic cast of > the types, will it be able to distinguish between a json and a list of > values?. > Example: > > data = ["a", "b", "c"] > idList = [4,7,2] > > cursor.execute("update mytable set jsfield=%s where id = any(%s)", > (data, idList)) > > What will be the correct syntax in this case? You would do like in psycopg2. There isn't a single json type in python (it could be a list, dict, number, None...) so there is a "Json" wrapper to tell psycopg to pass e.g. a json number rather than a number-number: https://www.psycopg.org/docs/extras.html?highlight=json#json-adaptation What you would do, both in psycopg2 and 3, would be something like: cursor.execute("update mytable set jsfield=%s where id = any(%s)", (Json(data), idList)) Code like this should work in both versions. Cheers -- Daniele