Skip to content

onConflictIgnore() with an empty set of fields generates invalid SQL #88

Open
@aboisvert

Description

@aboisvert

Databases like Postgres support ON CONFLICT IGNORE without specifying fields to allow ignoring the INSERT/UPDATE statement on any duplicate key violation.

Currently scalasql seems to generate invalid SQL when the fields clause is empty,

org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
  Position: 117
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2733)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2420)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:372)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:517)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:434)
	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:194)
	at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:137)
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
	at scalasql.core.DbApi$Impl$$anon$1.generate$$anonfun$2(DbApi.scala:473)
	at scalasql.core.DbApi$Impl.configureRunCloseStatement(DbApi.scala:563)
	at scalasql.core.DbApi$Impl$$anon$1.generate(DbApi.scala:472)
	at geny.Generator.foreach(Generator.scala:51)
	at geny.Generator.foreach$(Generator.scala:33)
	at scalasql.core.DbApi$Impl$$anon$1.foreach(DbApi.scala:460)
	at geny.Generator.toBuffer(Generator.scala:132)
	at geny.Generator.toBuffer$(Generator.scala:33)
	at scalasql.core.DbApi$Impl$$anon$1.toBuffer(DbApi.scala:460)
	at geny.Generator.toVector(Generator.scala:140)
	at geny.Generator.toVector$(Generator.scala:33)
	at scalasql.core.DbApi$Impl$$anon$1.toVector(DbApi.scala:460)
	at scalasql.core.DbApi$Impl.run(DbApi.scala:276)

I intend to submit a PR when I have time, just reporting for awareness at this time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions