pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mike Sofen <msofen@runbox.com>
To: 'tao tony' <tonytao0505@outlook.com>
To: pgsql-general@postgresql.org
Subject: RE: copy error with  json/jsonb types
Date: Thu, 30 Nov 2017 05:02:46 -0800
Message-ID: <05eb01d369db$86700940$93501bc0$@runbox.com> (raw)
In-Reply-To: <MWHPR13MB138974273F25E3F50980739BAA380@MWHPR13MB1389.namprd13.prod.outlook.com>
References: <MWHPR13MB138974273F25E3F50980739BAA380@MWHPR13MB1389.namprd13.prod.outlook.com>

From: tao tony [mailto:tonytao0505@outlook.com] 
Sent: Wednesday, November 29, 2017 10:02 PM



I'm using copy and jdbc copyin to build load data to pg,data type in table
is jsonb.postgresql version are 9.6 and 10.0.  Some records with escape
characters would be failed with error"ERROR:  invalid input syntax for type
json" but when using insert they could be executed successfully.

please kindly tell me how to fix this issue?

here is the table.

hdb=# \d salejsonb
             Table "public.salejsonb"
 Column  | Type  | Collation | Nullable | Default 
---------+-------+-----------+----------+---------
 jsonval | jsonb |           |          | 

======================================

I may be old school, but it would be rare situation where I'd be using an
ETL process - and I consider the Copy function to be an extract and load
part of that - to go directly into a live/final/production table.

 

Instead, I "always" use a staging table that is much more tolerant of
errors.  In this case, I'd create a table with the one column with a
datatype of "text".   Now run the copy command, the data will land without
error, then you can either devise processes that detect and fix invalid json
or do a proper error out from the db, and on receiving proper json,
proceeding to do a guaranteed good insert into your final jsonb table.  If
you were able to land the data in that staging table and then render it, you
may be able to find a pattern in the invalid escape characters that you
could fix on the fly on the insert from staging to final.

 

Mike Sofen

view thread (3+ messages)  latest in thread

Message-ID: <05eb01d369db$86700940$93501bc0$@runbox.com>
Permalink:  ../05eb01d369db$86700940$93501bc0$@runbox.com/
Also on:    postgresql.org/message-id/05eb01d369db$86700940$93501bc0$@runbox.com

 · 

reply

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-general@postgresql.org
  Cc: msofen@runbox.com, tonytao0505@outlook.com
  Subject: Re: copy error with  json/jsonb types
  In-Reply-To: <05eb01d369db$86700940$93501bc0$@runbox.com>
  References: <MWHPR13MB138974273F25E3F50980739BAA380@MWHPR13MB1389.namprd13.prod.outlook.com> <05eb01d369db$86700940$93501bc0$@runbox.com>

* 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