Give a more specific error message if you try to COMMIT, ROLLBACK or COPY
authorHeikki Linnakangas
Fri, 29 Oct 2010 08:41:28 +0000 (11:41 +0300)
committerHeikki Linnakangas
Fri, 29 Oct 2010 08:44:54 +0000 (11:44 +0300)
FROM STDIN in PL/pgSQL. We alread did this for dynamic EXECUTE statements,
ie. "EXECUTE 'COMMIT'", but not otherwise.

src/pl/plpgsql/src/pl_exec.c

index 4e9afd360b116239b2ce5b50a2693be2b326f871..3d20fa72c25f3b5cdf6dfb0d9471274603a87b2f 100644 (file)
@@ -2889,6 +2889,17 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
            exec_set_found(estate, false);
            break;
 
+           /* Some SPI errors deserve specific error messages */
+       case SPI_ERROR_COPY:
+           ereport(ERROR,
+                   (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                    errmsg("cannot COPY to/from client in PL/pgSQL")));
+       case SPI_ERROR_TRANSACTION:
+           ereport(ERROR,
+                   (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                    errmsg("cannot begin/end transactions in PL/pgSQL"),
+           errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
+
        default:
            elog(ERROR, "SPI_execute_plan_with_paramlist failed executing query \"%s\": %s",
                 expr->query, SPI_result_code_string(rc));