cockroachdb / cockroachdb/cockroach

sql,plpgsql: repeated notices after error

Open
#122,265 0 comments 0 reactions 0 assignees View on GitHub
A-sql-plpgsql A-sql-routine C-bug O-qa T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

The following example shows a case where notices printed from a successful routine invocation appear to be repeated on subsequent `CREATE PROCEDURE` statements that fail:
```
CREATE PROCEDURE test_proc6(a int, INOUT b int, INOUT c int)
LANGUAGE plpgsql
AS $$
BEGIN
b := b * a;
c := c * a;
END;
$$;

CALL test_proc6(2, 3, 4);

CREATE OR REPLACE PROCEDURE foo() LANGUAGE plpgsql
AS $$
DECLARE
x int := 3;
y int := 4;
BEGIN
CALL test_proc6(2, x, y);
RAISE INFO 'x = %, y = %', x, y;
CALL test_proc6(2, y, x);
RAISE INFO 'x = %, y = %', x, y;
END;
$$;

CALL foo();

CREATE OR REPLACE PROCEDURE foo() LANGUAGE plpgsql
AS $$
DECLARE
x int := 3;
y int := 4;
BEGIN
CALL test_proc6(2, x + 1, y); -- error
RAISE INFO 'x = %, y = %', x, y;
END;
$$;

CALL foo();

CREATE OR REPLACE PROCEDURE foo() LANGUAGE plpgsql
AS $$
DECLARE
x constant int := 3;
y int := 4;
BEGIN
CALL test_proc6(2, x, y); -- error because x is constant
END;
$$;

CALL foo();
```
Result (note the repeated `INFO` lines):
```
CREATE PROCEDURE

Time: 63ms total (execution 37ms / network 26ms)

b | c
----+----
6 | 8
(1 row)

Time: 10ms total (execution 10ms / network 0ms)

CREATE PROCEDURE

Time: 71ms total (execution 26ms / network 44ms)

INFO: x = 6, y = 8
SQLSTATE: 00000
INFO: x = 12, y = 16
SQLSTATE: 00000
CALL

Time: 1ms total (execution 1ms / network 0ms)

ERROR: procedure parameter "x + 1" is an output parameter but corresponding argument is not writable
SQLSTATE: 42601
INFO: x = 6, y = 8
SQLSTATE: 00000
INFO: x = 12, y = 16
SQLSTATE: 00000
CALL

Time: 1ms total (execution 1ms / network 0ms)

ERROR: variable "x" is declared CONSTANT
SQLSTATE: 22005
INFO: x = 6, y = 8
SQLSTATE: 00000
INFO: x = 12, y = 16
SQLSTATE: 00000
CALL

Time: 1ms total (execution 1ms / network 0ms)
```

Jira issue: CRDB-37781

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.