In the wake of
84f5c2908, it's no longer necessary for plpgsql to
handle SET/RESET specially. The point of that was just to avoid
taking a new transaction snapshot prematurely, which the regular code
path through _SPI_execute_plan() now does just fine (in fact better,
since it now does the right thing for LOCK too). Hence, rip out a
few lines of code, going back to the old way of treating SET/RESET
as a generic SQL command. This essentially reverts all but the
test cases from
b981275b6.
Discussion: https://postgr.es/m/15990-
eee2ac466b11293d@postgresql.org
$$;
ERROR: SET TRANSACTION ISOLATION LEVEL must be called before any query
CONTEXT: SQL statement "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ"
-PL/pgSQL function inline_code_block line 3 at SET
+PL/pgSQL function inline_code_block line 3 at SQL statement
DO LANGUAGE plpgsql $$
BEGIN
SAVEPOINT foo;
PLpgSQL_stmt_commit *stmt);
static int exec_stmt_rollback(PLpgSQL_execstate *estate,
PLpgSQL_stmt_rollback *stmt);
-static int exec_stmt_set(PLpgSQL_execstate *estate,
- PLpgSQL_stmt_set *stmt);
static void plpgsql_estate_setup(PLpgSQL_execstate *estate,
PLpgSQL_function *func,
rc = exec_stmt_rollback(estate, (PLpgSQL_stmt_rollback *) stmt);
break;
- case PLPGSQL_STMT_SET:
- rc = exec_stmt_set(estate, (PLpgSQL_stmt_set *) stmt);
- break;
-
default:
/* point err_stmt to parent, since this one seems corrupt */
estate->err_stmt = save_estmt;
return PLPGSQL_RC_OK;
}
-/*
- * exec_stmt_set
- *
- * Execute SET/RESET statement.
- *
- * We just parse and execute the statement normally, but we have to do it
- * without setting a snapshot, for things like SET TRANSACTION.
- * XXX spi.c now handles this correctly, so we no longer need a special case.
- */
-static int
-exec_stmt_set(PLpgSQL_execstate *estate, PLpgSQL_stmt_set *stmt)
-{
- PLpgSQL_expr *expr = stmt->expr;
- SPIExecuteOptions options;
- int rc;
-
- if (expr->plan == NULL)
- exec_prepare_plan(estate, expr, 0);
-
- memset(&options, 0, sizeof(options));
- options.read_only = estate->readonly_func;
-
- rc = SPI_execute_plan_extended(expr->plan, &options);
-
- if (rc != SPI_OK_UTILITY)
- elog(ERROR, "SPI_execute_plan_extended failed executing query \"%s\": %s",
- expr->query, SPI_result_code_string(rc));
-
- return PLPGSQL_RC_OK;
-}
-
/* ----------
* exec_assign_expr Put an expression's result into a variable.
* ----------
return "COMMIT";
case PLPGSQL_STMT_ROLLBACK:
return "ROLLBACK";
- case PLPGSQL_STMT_SET:
- return "SET";
}
return "unknown";
static void free_call(PLpgSQL_stmt_call *stmt);
static void free_commit(PLpgSQL_stmt_commit *stmt);
static void free_rollback(PLpgSQL_stmt_rollback *stmt);
-static void free_set(PLpgSQL_stmt_set *stmt);
static void free_expr(PLpgSQL_expr *expr);
case PLPGSQL_STMT_ROLLBACK:
free_rollback((PLpgSQL_stmt_rollback *) stmt);
break;
- case PLPGSQL_STMT_SET:
- free_set((PLpgSQL_stmt_set *) stmt);
- break;
default:
elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
break;
{
}
-static void
-free_set(PLpgSQL_stmt_set *stmt)
-{
- free_expr(stmt->expr);
-}
-
static void
free_exit(PLpgSQL_stmt_exit *stmt)
{
static void dump_call(PLpgSQL_stmt_call *stmt);
static void dump_commit(PLpgSQL_stmt_commit *stmt);
static void dump_rollback(PLpgSQL_stmt_rollback *stmt);
-static void dump_set(PLpgSQL_stmt_set *stmt);
static void dump_expr(PLpgSQL_expr *expr);
case PLPGSQL_STMT_ROLLBACK:
dump_rollback((PLpgSQL_stmt_rollback *) stmt);
break;
- case PLPGSQL_STMT_SET:
- dump_set((PLpgSQL_stmt_set *) stmt);
- break;
default:
elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
break;
printf("ROLLBACK\n");
}
-static void
-dump_set(PLpgSQL_stmt_set *stmt)
-{
- dump_ind();
- printf("%s\n", stmt->expr->query);
-}
-
static void
dump_exit(PLpgSQL_stmt_exit *stmt)
{
%type <stmt> stmt_return stmt_raise stmt_assert stmt_execsql
%type <stmt> stmt_dynexecute stmt_for stmt_perform stmt_call stmt_getdiag
%type <stmt> stmt_open stmt_fetch stmt_move stmt_close stmt_null
-%type <stmt> stmt_commit stmt_rollback stmt_set
+%type <stmt> stmt_commit stmt_rollback
%type <stmt> stmt_case stmt_foreach_a
%type <list> proc_exceptions
%token <keyword> K_QUERY
%token <keyword> K_RAISE
%token <keyword> K_RELATIVE
-%token <keyword> K_RESET
%token <keyword> K_RETURN
%token <keyword> K_RETURNED_SQLSTATE
%token <keyword> K_REVERSE
%token <keyword> K_SCHEMA
%token <keyword> K_SCHEMA_NAME
%token <keyword> K_SCROLL
-%token <keyword> K_SET
%token <keyword> K_SLICE
%token <keyword> K_SQLSTATE
%token <keyword> K_STACKED
{ $$ = $1; }
| stmt_rollback
{ $$ = $1; }
- | stmt_set
- { $$ = $1; }
;
stmt_perform : K_PERFORM
| /* EMPTY */ { $$ = false; }
;
-stmt_set : K_SET
- {
- PLpgSQL_stmt_set *new;
-
- new = palloc0(sizeof(PLpgSQL_stmt_set));
- new->cmd_type = PLPGSQL_STMT_SET;
- new->lineno = plpgsql_location_to_lineno(@1);
- new->stmtid = ++plpgsql_curr_compile->nstatements;
- plpgsql_push_back_token(K_SET);
- new->expr = read_sql_stmt();
-
- $$ = (PLpgSQL_stmt *)new;
- }
- | K_RESET
- {
- PLpgSQL_stmt_set *new;
-
- new = palloc0(sizeof(PLpgSQL_stmt_set));
- new->cmd_type = PLPGSQL_STMT_SET;
- new->lineno = plpgsql_location_to_lineno(@1);
- new->stmtid = ++plpgsql_curr_compile->nstatements;
- plpgsql_push_back_token(K_RESET);
- new->expr = read_sql_stmt();
-
- $$ = (PLpgSQL_stmt *)new;
- }
- ;
-
cursor_variable : T_DATUM
{
| K_QUERY
| K_RAISE
| K_RELATIVE
- | K_RESET
| K_RETURN
| K_RETURNED_SQLSTATE
| K_REVERSE
| K_SCHEMA
| K_SCHEMA_NAME
| K_SCROLL
- | K_SET
| K_SLICE
| K_SQLSTATE
| K_STACKED
PG_KEYWORD("query", K_QUERY)
PG_KEYWORD("raise", K_RAISE)
PG_KEYWORD("relative", K_RELATIVE)
-PG_KEYWORD("reset", K_RESET)
PG_KEYWORD("return", K_RETURN)
PG_KEYWORD("returned_sqlstate", K_RETURNED_SQLSTATE)
PG_KEYWORD("reverse", K_REVERSE)
PG_KEYWORD("schema", K_SCHEMA)
PG_KEYWORD("schema_name", K_SCHEMA_NAME)
PG_KEYWORD("scroll", K_SCROLL)
-PG_KEYWORD("set", K_SET)
PG_KEYWORD("slice", K_SLICE)
PG_KEYWORD("sqlstate", K_SQLSTATE)
PG_KEYWORD("stacked", K_STACKED)
PLPGSQL_STMT_PERFORM,
PLPGSQL_STMT_CALL,
PLPGSQL_STMT_COMMIT,
- PLPGSQL_STMT_ROLLBACK,
- PLPGSQL_STMT_SET
+ PLPGSQL_STMT_ROLLBACK
} PLpgSQL_stmt_type;
/*
bool chain;
} PLpgSQL_stmt_rollback;
-/*
- * SET statement
- */
-typedef struct PLpgSQL_stmt_set
-{
- PLpgSQL_stmt_type cmd_type;
- int lineno;
- unsigned int stmtid;
- PLpgSQL_expr *expr;
-} PLpgSQL_stmt_set;
-
/*
* GET DIAGNOSTICS item
*/