From: Tom Lane <tgl@sss.pgh.pa.us>
To: Арсен Арутюнян <arutar@bk.ru>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Error in SPI_execute_plan (when inserting JSON from C code first { simboll is lost)
Date: Mon, 26 Jun 2017 18:59:27 -0400
Message-ID: <24940.1498517967@sss.pgh.pa.us> (raw)
In-Reply-To: <1498515664.231254063@f472.i.mail.ru>
References: <1498515664.231254063@f472.i.mail.ru>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
=?UTF-8?B?0JDRgNGB0LXQvSDQkNGA0YPRgtGO0L3Rj9C9?= <arutar@bk.ru> writes:
> StringInfo JsonObject = makeStringInfo();
> appendStringInfoString(JsonObject, "{\"ObjectName\":\"Bug Json Object\",\"Type\":227,\"Command\":88}");
> Datum Values[2];
> Values[0] = Int32GetDatum(227);
> Values[1] = CStringGetDatum(JsonObject->data);
That's certainly not going to work, because a CString datum doesn't
have the same representation as a JSON datum.
I think you could get away with using CStringGetTextDatum, relying on
the equivalent physical representations of JSON and text. But it
wouldn't be a terribly good idea IMO, partly because you'd be passing
up validity checking on the JSON string; plus you could never make
that work for JSONB. What you really should do instead is pass the
CString to JSON's input function, say
Values[1] = OidInputFunctionCall(F_JSON_IN, JsonObject->data, JSONOID, -1);
This is still cheating a bit --- it knows more than it ought to about
what to pass for typioparam --- but it's unlikely to break.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, arutar@bk.ru
Subject: Re: Error in SPI_execute_plan (when inserting JSON from C code first { simboll is lost)
In-Reply-To: <24940.1498517967@sss.pgh.pa.us>
References: <1498515664.231254063@f472.i.mail.ru> <24940.1498517967@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox