1

我有以下对 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
      """

如果我使用updateupdateAndRetrieveGeneratedKeylocalTx我得到org.postgresql.util.PSQLException: A result was returned when none was expected.. 如果我使用singleinside,readOnly我会得到类似... cannot perform an insert in a read only query. 解决这个问题的正确方法是什么?

4

0 回答 0