Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMt5x-0005IM-Ln for pgsql-interfaces@arkaria.postgresql.org; Wed, 23 Feb 2022 14:58:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nMt5w-0004Do-AO for pgsql-interfaces@arkaria.postgresql.org; Wed, 23 Feb 2022 14:58:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nMt5w-0004Df-1T for pgsql-interfaces@lists.postgresql.org; Wed, 23 Feb 2022 14:58:20 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nMt5t-0001um-Kz for pgsql-interfaces@lists.postgresql.org; Wed, 23 Feb 2022 14:58:18 +0000 Received: by mail-ej1-x629.google.com with SMTP id qx21so52884193ejb.13 for ; Wed, 23 Feb 2022 06:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=0BOMhjaDXK4HbBHx9Q0uEtkIFH1xA1ZXA+z+BbUsT+E=; b=S0ZvypAFpqDo7BJPJAcpic3Z7hkzigYTTL61CfWjCtpPR3e7zpXFQEXugW9DagAtC6 J+UEKtOZQL4tNvhP8lqh/i7XzlNqRVRZHLA9c21w+jUPJWVYKINHuytzh8flTlvx4eC+ WTXCFeG6d+/6R606x9NOFaumx+mUOL2g540BEdtUp2/Nrd5km5tKWfpJGsy1qrpqwCNq mXYRtskD1z//7F8gmZ10soUuR2ue8TYcEPmgzVH8N2AH3n5ea6DXZnssyyAdnfCyCAZX fZ8fHSijQ5eNDeVFm3oqwIns59BPSTDnVBsKWFWrnVyeCHK7RG3yRzQtVlhlM2sj9rDt p/fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=0BOMhjaDXK4HbBHx9Q0uEtkIFH1xA1ZXA+z+BbUsT+E=; b=BM7ugbJpRc8Ew+6P+Cs4cG6lRCRr+ZsTTVJq1LRBXFgT981LrnZFyD9QPsoU2o7W0s 5VrMIN6+FBvay+KYu4Vkdq1QZA+9E6neQthDxGee7pq37vDO4IwMw7IuekVpzTz4OYMo ofNLcitwLb0m8szxBeFs5AcTchEndyVS3xvKkkRleLtXqA8YfYELcOLaI811kudpqki6 XYM8swbl37NMHnGX5GyjbtbLGvyiMfkMCsmwDs93KMx5ulJFtj7ogp5acriBheKBKtU4 x0aZY94yBZS/S60fL9Nok/l/2X74rnkV0yQLXup61XScjIdkziQLRG3vQ0pKoJVYa6cc U/Vg== X-Gm-Message-State: AOAM530+FllC8xxYNE5202tTD5RkiMD2iSz1XN6AuVicfF6Nq9Cs5cUG /3K9wOwQhRxE27jQ9h7lYfnHtoOf2snID27mlT/qHUMzVsZDcJff X-Google-Smtp-Source: ABdhPJwH71W7YJQeMEW8kBHgxRYEBcw8/XSsMIL7QvVsflpsv5SChiJlDV3B8GbgoeTW0LGQgPEuI4Vmm7Y46hben1s= X-Received: by 2002:a17:906:9445:b0:6cf:7421:576c with SMTP id z5-20020a170906944500b006cf7421576cmr98105ejx.538.1645628295825; Wed, 23 Feb 2022 06:58:15 -0800 (PST) MIME-Version: 1.0 From: Charles Kong Date: Wed, 23 Feb 2022 14:58:04 +0000 Message-ID: Subject: Use java interface "setArray" to insert the array of user-defined type to table To: pgsql-interfaces@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000014dd305d8b0b2e5" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000014dd305d8b0b2e5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi all, I use a user-defined type in =E2=80=9Cschema.sql=E2=80=9D CREATE TYPE infoEntity AS ( "entity_id" bigint, "seq" integer, "message" varchar(255) ) in java code: java_infoEntity[] infoEntityArray; //java_infoEntity is the class with the same member variables. infoEntityArray =3D new java_infoEntity[3]; infoEntityArray[0] =3D new java_infoEntity(); .... //info_Entity's type is user-defined type "infoEntity". sql =3D "insert into \"T_abc\" (info_Entity) values(?);"; statement =3D conn.prepareStatement( sql ); Array array =3D conn.createArrayOf("infoEntity", infoEntityArray); statement.setArray(1,array); statement.addBatch(); statement.executeBatch(); .... .... Sql throw exception: sqlException: SQLState: 22P02 Error Code: 0 Error Message: Batch entry 0 insert into "T_abc" (info_Entity) values('{"com.xxx.java_infoEntity@597d57aa"}') was aborted: ERROR: malformed record literal: " com.xxx.java_infoEntity@597d57aa" *How to cope with it?* --000000000000014dd305d8b0b2e5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi all,
I use a user-defined type in =E2=80=9Cschema.s= ql=E2=80=9D
CREATE TYPE infoEntity AS (
=C2=A0 =C2=A0 "en= tity_id" bigint,
=C2=A0 =C2=A0 "seq" integer,
=C2=A0 = =C2=A0 "message" varchar(255)
)

i= n java code:
java_infoEntity[] infoEntityArray; //java_infoEntity= is the class with the same member variables.
infoEntityArray= =C2=A0=3D new java_infoEntity[3];
infoEntityArray[0] =3D new = java_infoEntity();
....

//info_Entity= 9;s type is user-defined type "infoEntity".=C2=A0
sql = =3D "insert into \"T_abc\" (info_Entity) values(?);"; statement =3D conn.prepareStatement( sql );
Array array =3D = conn.createArrayOf("infoEntity",=C2=A0 infoEntityArray);
statement.setArray(1,array);
statement.addBatch(= );
statement.executeBatch();
....
....
Sql throw exception:=C2=A0
sqlExcepti= on:=C2=A0 SQLState: 22P02 Error Code: 0 Error Message: Batch entry 0 insert= into "T_abc" (info_Entity) val= ues('{"com.xxx.java_infoEntity@597d57aa"}') was aborted: = ERROR: malformed record literal: "co= m.xxx.java_infoEntity@597d57aa"

How to cope with it?

--000000000000014dd305d8b0b2e5--