cockroachdb / cockroachdb/cockroach
plpgsql: incorrect handling of tuple star expressions
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Expressions like `(foo).*` (where `foo` is a tuple) should expand out into an expression for each of the tuple elements, except in a few cases like function invocations like `f((foo).*)`. We don't currently do this for PL/pgSQL expressions, leading to examples like the following:
Setup:
```
create type typ as (x bool);
```
Case with RETURN statement expression:
```
root@localhost:26257/defaultdb> CREATE FUNCTION f(foo typ) RETURNS BOOL LANGUAGE PLpgSQL AS $$
-> BEGIN
-> RAISE NOTICE '%', foo;
-> RETURN (foo).*;
-> END;
-> $$;
CREATE FUNCTION
Time: 52ms total (execution 24ms / network 28ms)
root@localhost:26257/defaultdb> select f(row(false));
NOTICE: (f)
ERROR: could not parse "(f)" as type bool: invalid bool value
SQLSTATE: 22P02
```
Case with IF statement conditional expression:
```
root@localhost:26257/defaultdb> CREATE FUNCTION f(x typ) RETURNS INT LANGUAGE PLpgSQL AS $$
-> BEGIN
-> IF (x).* THEN
-> RETURN 1;
-> ELSE
-> RETURN 0;
-> END IF;
-> END
-> $$;
CREATE FUNCTION
Time: 93ms total (execution 58ms / network 35ms)
root@localhost:26257/defaultdb> select f(row(true));
ERROR: could not parse "(t)" as type bool: invalid bool value
SQLSTATE: 22P02
```
Both of these examples should evaluate successfully, but instead fail because the tuple-star expression is not correctly expanded.
Jira issue: CRDB-48449
Contributor guide
Assessment
This issue has not been assessed yet.