ScalikeJDBC:如何在Postgresql数据库上选择或插入查询?

时间:2019-03-07 10:20:23

标签: postgresql scala scalikejdbc

我有以下要对Postgresql数据库执行的SQL代码:

    sql"""WITH s AS (
             SELECT id
             FROM $tableName
             WHERE $columnName = $value
         ), i AS (
             INSERT INTO $tableName ($columnName)
            SELECT $value
            WHERE NOT EXISTS (
                SELECT id
                FROM $tableName
                WHERE $columnName = $value
            )
            RETURNING id
         )
         SELECT id
         FROM i
         UNION ALL
         SELECT id
         FROM s
      """

如果我在update中使用updateAndRetrieveGeneratedKeylocalTx,则会得到org.postgresql.util.PSQLException: A result was returned when none was expected.。如果在single中使用readOnly,则会得到类似... cannot perform an insert in a read only query的信息。 正确的解决方法是什么?

0 个答案:

没有答案