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 1hakgV-0003BP-LW for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Jun 2019 17:35:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hakgU-0007TL-Gg for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Jun 2019 17:35:46 +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 1hakgU-0007Pr-5X for pgsql-bugs@lists.postgresql.org; Tue, 11 Jun 2019 17:35:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hakgN-0004Sn-Sk for pgsql-bugs@lists.postgresql.org; Tue, 11 Jun 2019 17:35:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x5BHZYiP017309; Tue, 11 Jun 2019 13:35:35 -0400 From: Tom Lane To: Andrew Dunstan cc: Jeff Janes , Robert Vollmert , pgsql-bugs@lists.postgresql.org Subject: Re: inconsistent behaviour of json_to_record and friends with embedded json In-reply-to: <19461.1559506457@sss.pgh.pa.us> References: <19461.1559506457@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 02 Jun 2019 16:14:17 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17307.1560274534.1@sss.pgh.pa.us> Date: Tue, 11 Jun 2019 13:35:34 -0400 Message-ID: <17308.1560274534@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > I agree. It looks to me like the problem is this over-optimistic > assumption: > /* > * Add quotes around string value (should be already escaped) if > * converting to json/jsonb. > */ > No, it's *not* already escaped. Fixing the code to use escape_json() > is a bit tedious, because for some reason that function wasn't designed > to support non-null-terminated input, but with the attached patch we get > what seems to me like sane behavior: Hearing no comments, I've pushed this patch. I also rewrote the documentation to provide something approaching a specification for what json_to_record() and friends do. regards, tom lane