Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V5Jue-0006k4-5X for pgsql-bugs@arkaria.postgresql.org; Fri, 02 Aug 2013 18:17:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V5Jud-0007aY-Kr for pgsql-bugs@arkaria.postgresql.org; Fri, 02 Aug 2013 18:17:15 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V5Juc-0007aS-Rs for pgsql-bugs@postgresql.org; Fri, 02 Aug 2013 18:17:15 +0000 Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V5JuY-0007zf-L1 for pgsql-bugs@postgresql.org; Fri, 02 Aug 2013 18:17:14 +0000 Received: from mfilter6-d.gandi.net (mfilter6-d.gandi.net [217.70.178.135]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 13D26172090; Fri, 2 Aug 2013 20:16:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter6-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter6-d.gandi.net (mfilter6-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id Z80bZpd+fHHI; Fri, 2 Aug 2013 20:16:44 +0200 (CEST) X-Originating-IP: 98.27.58.255 Received: from [192.168.10.146] (cpe-098-027-058-255.nc.res.rr.com [98.27.58.255]) (Authenticated sender: adsend@dunslane.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 22EC8172085; Fri, 2 Aug 2013 20:16:41 +0200 (CEST) Message-ID: <51FBF787.5000408@dunslane.net> Date: Fri, 02 Aug 2013 14:16:39 -0400 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Bruce Momjian CC: jaroslav.potapov@gmail.com, pgsql-bugs@postgresql.org Subject: Re: BUG #8293: There are no methods to convert json scalar text to text in v9.3 beta2 References: <20130802170436.GB14543@momjian.us> In-Reply-To: <20130802170436.GB14543@momjian.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.1 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 08/02/2013 01:04 PM, Bruce Momjian wrote: > On Wed, Jul 10, 2013 at 07:07:54PM +0000, jaroslav.potapov@gmail.com wrote: >> The following bug has been logged on the website: >> >> Bug reference: 8293 >> Logged by: Yaroslav Potapov >> Email address: jaroslav.potapov@gmail.com >> PostgreSQL version: Unsupported/Unknown >> Operating system: All >> Description: >> >> SELECT '"a\"b"'::json::text >> >> >> returns text: '"a\"b"' , >> but it must return 'a"b' in my opinion. > I see you didn't get a reply, so let me try. I am no JSON expert, but I > think what is happening is that the system stores "a\"b" because that is > what a JSON/Javascript interpreter would need to understand that value. > It would convert "a\"b" to a"b. If we just stored a"b, the interpreter > would throw an error on input. Well, yes, although the shorter answer is simply that we would not be storing legal JSON, which is defined by a standard, not by the requirements of interpreters. There is no specific cast to text for json. The cast therefore calls the type's output function, which of course delivers the json string. To do as the OP suggests would require us to treat JSON scalar strings as special, since we would certainly not want to de-escape any JSON that wasn't just a scalar string. e.g. removing quotes or backslashes in this would be a major error: select '{"\"a": "b\"c"}'::json::text; IOW, this isn't a bug in my view. What we should possibly provide is a function to de-escape JSON scalar strings explicitly. It would be a simple extension to write, particularly for 9.3 where the JSON parser is hookable. (Or it could easily be added as a core function of course). cheers andrew -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs