Skip site navigation (1) Skip section navigation (2)

Re: [Q] storing JSON, problem with 'escapes'

From: Andrew McMillan <andrew(at)morphoss(dot)com>
To: V S P <toreason(at)fastmail(dot)fm>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: [Q] storing JSON, problem with 'escapes'
Date: 2008-11-21 10:28:46
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-php
On Fri, 2008-11-21 at 01:54 -0500, V S P wrote:
> Hi,
> I am using PHP's json_encode function on
> an array of strings
> that gives me back a JSON encoded string.
> Some of the elements in the string arrays have
> double quotes.  So PHP's json_encode correctly
> escapes them (according to JSON specifications)
> with \.
> For example here is a an array element
> "if( js_iop_lt(a,b) ){ VLADIKVLADIKVLADIKVLADIK("b2122") ;}"
> would get encoded in JSON as
> "if( js_iop_lt(a,b) ){ VLADIKVLADIKVLADIKVLADIK(\"b2122\") ;}"
> And that's correct.
> Now, the problem is that with PDO (or may be postgresql itself)
> I get 
> "if( js_iop_lt(a,b) ){ VLADIKVLADIKVLADIKVLADIK(\\"b2122\\") ;}"
> and I get then the POSTGRESQL warning
> WARNING:  nonstandard use of \\ in a string literal at character 240
> HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.

When you construct your SQL, if you are going to construct it as a
string, like:

INSERT INTO blah ( json_column )

You need to instead insert as:

INSERT INTO blah ( json_column )

The "E" in front of the string is a special PostgreSQL thing which
explains that the string is encoded with \ escaping.


particularly the box labelled 'caution' and the paragraph above it.

					Andrew McMillan.

andrew (AT) morphoss (DOT) com                            +64(272)DEBIAN
                 You have a truly strong individuality.

In response to


pgsql-php by date

Next:From: V S PDate: 2008-11-21 21:18:51
Subject: Re: [Q] storing JSON, problem with 'escapes'
Previous:From: V S PDate: 2008-11-21 07:43:56
Subject: Re: [Q] storing JSON, problem with 'escapes'

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group