JOOQ fails with PostgreSQL Custom Type as an Array: ERROR: malformed record literal -
i have following custom type on postgres:
create type my_custom_type ( field_a varchar, field_b numeric(10,3) ); and following table:
create table my_table ( col1 varchar(120) not null, custom_column my_custom_type, custom_column_array my_custom_type[] ); everything works fine when use custom type jooq:
@test public void testwithoutarray(){ mytablerecord record = dsl.newrecord(mytable.my_table); record.setcol1("my col1"); mycustomtype customtype = new mycustomtype(); customtype.setfielda("field val"); customtype.setfieldb(bigdecimal.one); record.setcustomcolumn(customtype); record.store(); } however, when try set value in field mapped custom type array, have following error:
@test public void testwitharray(){ mytablerecord record = dsl.newrecord(mytable.my_table); record.setcol1("my col1"); mycustomtyperecord customtype = new mycustomtyperecord(); customtype.setfielda("field val 1"); customtype.setfieldb(bigdecimal.one); mycustomtyperecord customtype2 = new mycustomtyperecord(); customtype2.setfielda("field val 2"); customtype2.setfieldb(bigdecimal.ten); record.setcustomcolumnarray(new mycustomtyperecord[]{customtype, customtype2}); record.store(); } org.jooq.exception.dataaccessexception: sql [insert "my_table" ("col1", "custom_column_array") values (?, ?::my_custom_type[]) returning "my_table"."col1"]; error: malformed record literal: "my_custom_type"(field val 1, 1)" detail: missing left parenthesis. @ org.jooq.impl.utils.translate(utils.java:1553) @ org.jooq.impl.defaultexecutecontext.sqlexception(defaultexecutecontext.java:571) @ org.jooq.impl.abstractquery.execute(abstractquery.java:347) @ org.jooq.impl.tablerecordimpl.storeinsert0(tablerecordimpl.java:176) @ org.jooq.impl.tablerecordimpl$1.operate(tablerecordimpl.java:142) @ org.jooq.impl.recorddelegate.operate(recorddelegate.java:123) @ org.jooq.impl.tablerecordimpl.storeinsert(tablerecordimpl.java:137) @ org.jooq.impl.updatablerecordimpl.store0(updatablerecordimpl.java:185) @ org.jooq.impl.updatablerecordimpl.access$000(updatablerecordimpl.java:85) @ org.jooq.impl.updatablerecordimpl$1.operate(updatablerecordimpl.java:135) @ org.jooq.impl.recorddelegate.operate(recorddelegate.java:123) @ org.jooq.impl.updatablerecordimpl.store(updatablerecordimpl.java:130) @ org.jooq.impl.updatablerecordimpl.store(updatablerecordimpl.java:123) the query generated jooq debugg following:
debug [main] org.jooq.tools.loggerlistener#debug:255 - executing query : insert "my_table" ("col1", "custom_column_array") values (?, ?::my_custom_type[]) returning "my_table"."col1" debug [main] org.jooq.tools.loggerlistener#debug:255 - -> bind values : insert "my_table" ("col1", "custom_column_array") values ('my col1', array[[udt], [udt]]) returning "my_table"."col1" am missing configuration or bug?
cheers
as stated in relevant issue (https://github.com/jooq/jooq/issues/4162), missing piece of support kind of postgresql functionality. answer given in issue far is:
unfortunately, area have work around couple of limitations of postgresql jdbc driver, doesn't implement sqldata , other api (see pgjdbc/pgjdbc#63).
currently, jooq binds arrays , udts strings. seems particular combination not yet supported. able work around limitation implementing own custom data type binding:
http://www.jooq.org/doc/latest/manual/code-generation/custom-data-type-bindings/
Comments
Post a Comment