1

I have the following SQL code I would to execute against a Postgresql db:

    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
      """

If I use update or updateAndRetrieveGeneratedKey within a localTx I get org.postgresql.util.PSQLException: A result was returned when none was expected.. If I use single within readOnly I get something like ... cannot perform an insert in a read only query. What is the proper way to go about this?

zaxme
  • 1,065
  • 11
  • 29

0 Answers0