Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plpgsql: error for txn control inside exception-handling block is eager #119750

Open
DrewKimball opened this issue Feb 28, 2024 · 0 comments
Open
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@DrewKimball
Copy link
Collaborator

DrewKimball commented Feb 28, 2024

This is a tracking issue for a difference in behavior between CRDB and postgres. Postgres does not allow COMMIT or ROLLBACK statements inside a PL/pgSQL block that has an exception handler. However, postgres checks this condition lazily, so that the error is only thrown if the transaction control statement is actually executed:

CREATE PROCEDURE p(a INT) LANGUAGE PLpgSQL AS $$
  BEGIN
    IF a > 0 THEN
      COMMIT;
    END IF;
  EXCEPTION WHEN division_by_zero THEN
    RAISE NOTICE 'foo';
  END;
$$;

CALL p(0); -- Postgres does not raise an error.
CALL p(1); -- Postgres raises an error.

CRDB eagerly checks for this situation, and throws the error in response to the CREATE PROCEDURE statement instead. This behavior is unlikely to change because users are unlikely to want to write such a stored procedure.

Jira issue: CRDB-36295

@DrewKimball DrewKimball added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

1 participant