Question

The following code seqment should insert a new entry and return it (with auto generated id). It works fine for PostgreSQL.

val ret = elementTableQuery.returning(elementTableQuery) += Element("Arg1", "Arg2", "Arg3")

The Exception which is thrown is:

JdbcSQLException: Invalid value "2" for parameter "columnIndex" [90008-172] (DbException.java:329)
org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
org.h2.message.DbException.get(DbException.java:169)
org.h2.message.DbException.getInvalidValueException(DbException.java:215)
org.h2.jdbc.JdbcResultSet.checkColumnIndex(JdbcResultSet.java:3088)
org.h2.jdbc.JdbcResultSet.get(JdbcResultSet.java:3116)
org.h2.jdbc.JdbcResultSet.getString(JdbcResultSet.java:279)
ch.xxx.test.data.ElementCreator$.create(InitialDataCreator.scala:199)

The statement also works (in PorstgreSQL and H2) if I remove the "returning" part. It also works if I only return the generated Id like:

val ret = elementTableQuery.returning(elementTableQuery.map(_.id)) += Element("Arg1", "Arg2", "Arg3")

I found a bug report (https://github.com/slick/slick/issues/230) which seems to concern the same problem but was closed because it could not be reproduced.

Should I open a new bug? Is there anything wrong with my query?

I am thankful for any input.

Was it helpful?

Solution 2

Looks like a bug. Please open an issue and provide us enough information to reproduce the problem. Thanks

OTHER TIPS

According to http://slick.typesafe.com/doc/2.0.0/queries.html#inserting

Note that many database systems only allow a single column to be returned which must be the table’s auto-incrementing primary key. If you ask for other columns a SlickException is thrown at runtime (unless the database actually supports it).

I am not completely sure, but it could be that H2 only allows returning the auto-incrementing primary key. That would explain why this exception is thrown.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top