You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
case class Bean2(id: Option[Long], code: String, col2: Int)
class UpsertTestTable2(tag: Tag) extends Table[Bean2](tag, "test_tab_upsert2") {
def id = column[Long]("id", O.AutoInc)
def code = column[String]("code")
def col2 = column[Int]("col2")
def * = (id.?, code, col2) <> (Bean2.tupled, Bean2.unapply)
def pk = primaryKey("pk_a", (code, col2))
}
val UpsertTests2 = TableQuery[UpsertTestTable2]
I use it like this: UpsertTests2.insertOrUpdate(Bean2(None, "aa", 3))
Observation 1 - Query looks strange: insert into "test_tab_upsert2" (code,col2) values (?,?) on conflict () do update set "code"=EXCLUDED."code","col2"=EXCLUDED."col2" where ? is null or ?=?
Observation 2 - Error I get:
org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
[info] Position: 72
[info] at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
[info] at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
[info] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
[info] at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
[info] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
[info] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:366)
[info] at slick.driver.JdbcActionComponent$InsertActionComposerImpl$InsertOrUpdateAction$$anonfun$nativeUpsert$1.apply(JdbcActionComponent.scala:560)
[info] at slick.driver.JdbcActionComponent$InsertActionComposerImpl$InsertOrUpdateAction$$anonfun$nativeUpsert$1.apply(JdbcActionComponent.scala:557)
[info] at slick.jdbc.JdbcBackend$SessionDef$class.withPreparedStatement(JdbcBackend.scala:347)
[info] at slick.jdbc.JdbcBackend$BaseSession.withPreparedStatement(JdbcBackend.scala:407)
[info] ...
Looking at code this is place where query is wrongly composed (line 96 in ExPostgresDriver.scala): private lazy val (pkSyms, softSyms) = insertingSyms.partition(_.options.contains(ColumnOption.PrimaryKey))
The text was updated successfully, but these errors were encountered:
@jozi-k Here I only fix it for pg native upsert implementation, which is on slick-pg side.
But I still need to fix it for pg emulating implementation and other dbs, which is on slick side.
While not necessarily the cause of this user's error, if you ever neglect to specify all Primary key columns in your Table class, you will get this very same error.
My table definition:
I use it like this:
UpsertTests2.insertOrUpdate(Bean2(None, "aa", 3))
Observation 1 - Query looks strange:
insert into "test_tab_upsert2" (code,col2) values (?,?) on conflict () do update set "code"=EXCLUDED."code","col2"=EXCLUDED."col2" where ? is null or ?=?
Observation 2 - Error I get:
Looking at code this is place where query is wrongly composed (line 96 in ExPostgresDriver.scala):
private lazy val (pkSyms, softSyms) = insertingSyms.partition(_.options.contains(ColumnOption.PrimaryKey))
The text was updated successfully, but these errors were encountered: