From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Curt Huffman <curt(dot)huffman(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Inserting JSON via Java PreparedStatment |
Date: | 2016-03-07 16:32:40 |
Message-ID: | CAKFQuwbZ-4_W2V0jSrrEkTRz62xJTum+Ld8QReyBXe_9g-A2mA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> pStmt.setString(11, dtlRec.toString());
> pStmt.setObject(11, dtlRec.toString());
>
> Which produce a different error:
>
> Event JSON: {"New MbrID":29}
>
> SQLException: ERROR: column "evtjson" is of type json but expression is of
> type character varying
>
> Hint: You will need to rewrite or cast the expression.
>
>
Take the hint, literally. You never did show the SQL but usually the
least complex way to solve this is to indeed transfer the data as a
string/text and then instruction PostgreSQL to convert (i.e., cast) it to
json.
SELECT (?)::json; <-- that ? parameter is seen as text; then you convert
it. The parentheses should be optional but I use them to emphasize the
point.
then
pStmt.setString(1, dtlRec.toString());
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2016-03-07 16:35:39 | Re: Inserting JSON via Java PreparedStatment |
Previous Message | Tom Lane | 2016-03-07 16:02:19 | Re: index problems (again) |