Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icZe0-0001Jl-4q for psycopg@arkaria.postgresql.org; Wed, 04 Dec 2019 18:45:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1icZdx-0002U7-Ok for psycopg@arkaria.postgresql.org; Wed, 04 Dec 2019 18:44:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icZdw-0002U0-Nb for psycopg@lists.postgresql.org; Wed, 04 Dec 2019 18:44:57 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1icZdp-0003E3-MG for psycopg@lists.postgresql.org; Wed, 04 Dec 2019 18:44:55 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id D241A2267E; Wed, 4 Dec 2019 13:44:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 04 Dec 2019 13:44:48 -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=7 /7Iuu1XTNcjBkshYiPvZaPTticiCUZQ+O2D/pm/VlM=; b=fvfgdKW1MYGbVIud/ DPsvFUwgtYdCWX1UKJq9cjCo2kxbf8oeR6HouOlclAQub9U30IP2dXffNcEb9Yk3 I6WDGC7UfZLlff/w0XDDQAaJ87MVBOdsM0XXdjq1GgxzMPw69179w/pyVm/5jevI 3AAeKBxWJjqhnrG9RUHItPPpiUvbTrqTRXztz+HnT7F8PBCDNT3TD9Vn1Lydkmvk Jv4YGRrnSmjPWkOclmohlUX434HEPcs6tGbVlbJRqRM64INGpT/fuQHDaZzEe7aO VmqO+53lZyPygLGEjGUG3bWiku3wq8E3Q6ef0c9Jj4QMzrpkLFEQuRzxHlC/ISwa 8wFgg== 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=7/7Iuu1XTNcjBkshYiPvZaPTticiCUZQ+O2D/pm/V lM=; b=pIz/oNGDrq3K5F3lOK6bSsVQcr3I25wE1/LU6Fg6IOFVGncRsSs9d0Vw7 LqrcgwOSYwBVLORvEH+2IXdw6i89vxieiUadOFUCLWatgfampHbqIenFwqn1bJGm K9m4z4YgXhXbTfuiqWjlgJjIuj0OyAOjc5zD4wRd46Pp38mD6jz8/oMSJNPCgTs9 Feat/5Ni5Ed5xHCB3jMkssvaWOzqV7qghVwY3FLutUGmyD2hZ9xP6jy3QGUle5se aLLYHbU+T+ftQun6KQ8QmZg3iHXJ/W3gdBMrNQF8S64NIaLlfqufUPiJ2jZKxTGH aBkeAwkAFyYJ+bHbQa8K5rW2xQUXA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudejledguddugecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesth ejredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepphhoshhtghhrvg hsqhhlrdhorhhgnecukfhppeejgedrleefrddutdehrddukeeinecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuve hluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from ranger.suse (74-93-105-186-washington.hfc.comcastbusiness.net [74.93.105.186]) by mail.messagingengine.com (Postfix) with ESMTPA id 1653480059; Wed, 4 Dec 2019 13:44:47 -0500 (EST) Subject: Re: Array of tuples as a parameter, with type casts To: Vladimir Ryabtsev Cc: psycopg@lists.postgresql.org References: From: Adrian Klaver Message-ID: <25c3598a-698f-8d0e-3659-791253b903ec@aklaver.com> Date: Wed, 4 Dec 2019 10:44:47 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.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 12/3/19 4:00 PM, Vladimir Ryabtsev wrote: > It does not change much, the error message just says it now expects > 'character varying'. > Anyway bigint problem is the next in the line. Yeah it is related to this: https://www.postgresql.org/docs/11/functions-array.html unnest(anyarray) setof anyelement Dealing with anyelement can be tricky. I tried out an alternate solution: json_query = "select * from json_to_recordset(%s) as t(a timestamp, b varchar, c bigint)" cur.execute(json_query,[Json([{'a': datetime.now().isoformat(), 'b': 'abc', 'c': 100},{'a': datetime.now().isoformat(), 'b': 'xyz', 'c': 200}])]) Which results in: test_(postgres)# select * from json_to_recordset(E'[{"a": "2019-12-04T10:40:22.823910", "b": "abc", "c": 100}, {"a": "2019-12-04T10:40:22.823918", "b": "xyz", "c": 200}]') as t(a timestamp, b varchar, c bigint) ; a | b | c ----------------------------+-----+----- 2019-12-04 10:40:22.82391 | abc | 100 2019-12-04 10:40:22.823918 | xyz | 200 (2 rows) > > -- > Regards, > Vladimir -- Adrian Klaver adrian.klaver@aklaver.com