exec-ddl
CREATE TABLE t (
  k INT PRIMARY KEY,
  i INT,
  s STRING
)
----

exec-ddl
CREATE PROCEDURE my_upsert(arg_k INT, new_i INT, new_s STRING) AS $$
  DECLARE
    c INT;
  BEGIN
    SELECT count(*) INTO c FROM t WHERE k = arg_k;
    IF c > 0 THEN
      UPDATE t SET i = new_i, s = new_s WHERE k = arg_k;
    ELSE
      INSERT INTO t VALUES (arg_k, new_i, new_s);
    END IF;
  END
$$ LANGUAGE PLpgSQL
----

build format=show-scalars
CALL my_upsert(1, 10, 'foo')
----
call
 └── procedure: my_upsert
      ├── args
      │    ├── const: 1
      │    ├── const: 10
      │    └── const: 'foo'
      ├── params: arg_k:1 new_i:2 new_s:3
      └── body
           └── limit
                ├── columns: "_stmt_exec_1":59
                ├── project
                │    ├── columns: "_stmt_exec_1":59
                │    ├── barrier
                │    │    ├── columns: c:4
                │    │    └── project
                │    │         ├── columns: c:4
                │    │         ├── values
                │    │         │    └── tuple
                │    │         └── projections
                │    │              └── cast: INT8 [as=c:4]
                │    │                   └── null
                │    └── projections
                │         └── udf: _stmt_exec_1 [as="_stmt_exec_1":59]
                │              ├── args
                │              │    ├── variable: arg_k:1
                │              │    ├── variable: new_i:2
                │              │    ├── variable: new_s:3
                │              │    └── variable: c:4
                │              ├── params: arg_k:5 new_i:6 new_s:7 c:8
                │              └── body
                │                   └── project
                │                        ├── columns: "_stmt_exec_ret_2":58
                │                        ├── barrier
                │                        │    ├── columns: c:57
                │                        │    └── project
                │                        │         ├── columns: c:57
                │                        │         ├── right-join (cross)
                │                        │         │    ├── columns: count_rows:14
                │                        │         │    ├── limit
                │                        │         │    │    ├── columns: count_rows:14!null
                │                        │         │    │    ├── scalar-group-by
                │                        │         │    │    │    ├── columns: count_rows:14!null
                │                        │         │    │    │    ├── project
                │                        │         │    │    │    │    └── select
                │                        │         │    │    │    │         ├── columns: k:9!null i:10 s:11 crdb_internal_mvcc_timestamp:12 tableoid:13
                │                        │         │    │    │    │         ├── scan t
                │                        │         │    │    │    │         │    └── columns: k:9!null i:10 s:11 crdb_internal_mvcc_timestamp:12 tableoid:13
                │                        │         │    │    │    │         └── filters
                │                        │         │    │    │    │              └── eq
                │                        │         │    │    │    │                   ├── variable: k:9
                │                        │         │    │    │    │                   └── variable: arg_k:5
                │                        │         │    │    │    └── aggregations
                │                        │         │    │    │         └── count-rows [as=count_rows:14]
                │                        │         │    │    └── const: 1
                │                        │         │    ├── values
                │                        │         │    │    └── tuple
                │                        │         │    └── filters (true)
                │                        │         └── projections
                │                        │              └── variable: count_rows:14 [as=c:57]
                │                        └── projections
                │                             └── udf: _stmt_exec_ret_2 [as="_stmt_exec_ret_2":58]
                │                                  ├── tail-call
                │                                  ├── args
                │                                  │    ├── variable: arg_k:5
                │                                  │    ├── variable: new_i:6
                │                                  │    ├── variable: new_s:7
                │                                  │    └── variable: c:57
                │                                  ├── params: arg_k:15 new_i:16 new_s:17 c:18
                │                                  └── body
                │                                       └── project
                │                                            ├── columns: stmt_if_6:56
                │                                            ├── values
                │                                            │    └── tuple
                │                                            └── projections
                │                                                 └── case [as=stmt_if_6:56]
                │                                                      ├── true
                │                                                      ├── when
                │                                                      │    ├── gt
                │                                                      │    │    ├── variable: c:18
                │                                                      │    │    └── const: 0
                │                                                      │    └── subquery
                │                                                      │         ├── tail-call
                │                                                      │         └── project
                │                                                      │              ├── columns: "_stmt_exec_4":41
                │                                                      │              ├── values
                │                                                      │              │    └── tuple
                │                                                      │              └── projections
                │                                                      │                   └── udf: _stmt_exec_4 [as="_stmt_exec_4":41]
                │                                                      │                        ├── tail-call
                │                                                      │                        ├── args
                │                                                      │                        │    ├── variable: arg_k:15
                │                                                      │                        │    ├── variable: new_i:16
                │                                                      │                        │    ├── variable: new_s:17
                │                                                      │                        │    └── variable: c:18
                │                                                      │                        ├── params: arg_k:24 new_i:25 new_s:26 c:27
                │                                                      │                        └── body
                │                                                      │                             ├── update t
                │                                                      │                             │    ├── columns: <none>
                │                                                      │                             │    ├── fetch columns: k:33 i:34 s:35
                │                                                      │                             │    ├── update-mapping:
                │                                                      │                             │    │    ├── i_new:38 => i:29
                │                                                      │                             │    │    └── s_new:39 => s:30
                │                                                      │                             │    └── project
                │                                                      │                             │         ├── columns: i_new:38 s_new:39 k:33!null i:34 s:35 crdb_internal_mvcc_timestamp:36 tableoid:37
                │                                                      │                             │         ├── select
                │                                                      │                             │         │    ├── columns: k:33!null i:34 s:35 crdb_internal_mvcc_timestamp:36 tableoid:37
                │                                                      │                             │         │    ├── scan t
                │                                                      │                             │         │    │    ├── columns: k:33!null i:34 s:35 crdb_internal_mvcc_timestamp:36 tableoid:37
                │                                                      │                             │         │    │    └── flags: avoid-full-scan
                │                                                      │                             │         │    └── filters
                │                                                      │                             │         │         └── eq
                │                                                      │                             │         │              ├── variable: k:33
                │                                                      │                             │         │              └── variable: arg_k:24
                │                                                      │                             │         └── projections
                │                                                      │                             │              ├── variable: new_i:25 [as=i_new:38]
                │                                                      │                             │              └── variable: new_s:26 [as=s_new:39]
                │                                                      │                             └── project
                │                                                      │                                  ├── columns: stmt_if_3:40
                │                                                      │                                  ├── values
                │                                                      │                                  │    └── tuple
                │                                                      │                                  └── projections
                │                                                      │                                       └── udf: stmt_if_3 [as=stmt_if_3:40]
                │                                                      │                                            ├── tail-call
                │                                                      │                                            ├── args
                │                                                      │                                            │    ├── variable: arg_k:24
                │                                                      │                                            │    ├── variable: new_i:25
                │                                                      │                                            │    ├── variable: new_s:26
                │                                                      │                                            │    └── variable: c:27
                │                                                      │                                            ├── params: arg_k:19 new_i:20 new_s:21 c:22
                │                                                      │                                            └── body
                │                                                      │                                                 └── project
                │                                                      │                                                      ├── columns: "_implicit_return":23
                │                                                      │                                                      ├── values
                │                                                      │                                                      │    └── tuple
                │                                                      │                                                      └── projections
                │                                                      │                                                           └── cast: VOID [as="_implicit_return":23]
                │                                                      │                                                                └── null
                │                                                      └── subquery
                │                                                           ├── tail-call
                │                                                           └── project
                │                                                                ├── columns: "_stmt_exec_5":55
                │                                                                ├── values
                │                                                                │    └── tuple
                │                                                                └── projections
                │                                                                     └── udf: _stmt_exec_5 [as="_stmt_exec_5":55]
                │                                                                          ├── tail-call
                │                                                                          ├── args
                │                                                                          │    ├── variable: arg_k:15
                │                                                                          │    ├── variable: new_i:16
                │                                                                          │    ├── variable: new_s:17
                │                                                                          │    └── variable: c:18
                │                                                                          ├── params: arg_k:42 new_i:43 new_s:44 c:45
                │                                                                          └── body
                │                                                                               ├── insert t
                │                                                                               │    ├── columns: <none>
                │                                                                               │    ├── insert-mapping:
                │                                                                               │    │    ├── column1:51 => k:46
                │                                                                               │    │    ├── column2:52 => i:47
                │                                                                               │    │    └── column3:53 => s:48
                │                                                                               │    └── values
                │                                                                               │         ├── columns: column1:51 column2:52 column3:53
                │                                                                               │         └── tuple
                │                                                                               │              ├── variable: arg_k:42
                │                                                                               │              ├── variable: new_i:43
                │                                                                               │              └── variable: new_s:44
                │                                                                               └── project
                │                                                                                    ├── columns: stmt_if_3:54
                │                                                                                    ├── values
                │                                                                                    │    └── tuple
                │                                                                                    └── projections
                │                                                                                         └── udf: stmt_if_3 [as=stmt_if_3:54]
                │                                                                                              ├── tail-call
                │                                                                                              ├── args
                │                                                                                              │    ├── variable: arg_k:42
                │                                                                                              │    ├── variable: new_i:43
                │                                                                                              │    ├── variable: new_s:44
                │                                                                                              │    └── variable: c:45
                │                                                                                              ├── params: arg_k:19 new_i:20 new_s:21 c:22
                │                                                                                              └── body
                │                                                                                                   └── project
                │                                                                                                        ├── columns: "_implicit_return":23
                │                                                                                                        ├── values
                │                                                                                                        │    └── tuple
                │                                                                                                        └── projections
                │                                                                                                             └── cast: VOID [as="_implicit_return":23]
                │                                                                                                                  └── null
                └── const: 1

# Case with nested blocks.
exec-ddl
CREATE OR REPLACE PROCEDURE p(x INT) AS $$
  DECLARE
    y INT := 10;
  BEGIN
    x := x + 1;
    y := y + 1;
    RAISE NOTICE '% %', x, y;
    DECLARE
      z INT := 100;
    BEGIN
      x := x + 1;
      y := y + 1;
      z := z + 1;
      RAISE NOTICE '% % %', x, y, z;
    END;
    x := x + 1;
    y := y + 1;
    RAISE NOTICE '% %', x, y;
  END
$$ LANGUAGE PLpgSQL;
----

build format=show-scalars
CALL p(5)
----
call
 └── procedure: p
      ├── args
      │    └── const: 5
      ├── params: x:1
      └── body
           └── limit
                ├── columns: "_stmt_raise_1":27
                ├── project
                │    ├── columns: "_stmt_raise_1":27
                │    ├── barrier
                │    │    ├── columns: x:3 y:4!null
                │    │    └── project
                │    │         ├── columns: y:4!null x:3
                │    │         ├── project
                │    │         │    ├── columns: x:3 y:2!null
                │    │         │    ├── project
                │    │         │    │    ├── columns: y:2!null
                │    │         │    │    ├── values
                │    │         │    │    │    └── tuple
                │    │         │    │    └── projections
                │    │         │    │         └── const: 10 [as=y:2]
                │    │         │    └── projections
                │    │         │         └── plus [as=x:3]
                │    │         │              ├── variable: x:1
                │    │         │              └── const: 1
                │    │         └── projections
                │    │              └── plus [as=y:4]
                │    │                   ├── variable: y:2
                │    │                   └── const: 1
                │    └── projections
                │         └── udf: _stmt_raise_1 [as="_stmt_raise_1":27]
                │              ├── args
                │              │    ├── variable: x:3
                │              │    └── variable: y:4
                │              ├── params: x:5 y:6
                │              └── body
                │                   ├── project
                │                   │    ├── columns: stmt_raise_2:7
                │                   │    ├── values
                │                   │    │    └── tuple
                │                   │    └── projections
                │                   │         └── function: crdb_internal.plpgsql_raise [as=stmt_raise_2:7]
                │                   │              ├── const: 'NOTICE'
                │                   │              ├── concat
                │                   │              │    ├── concat
                │                   │              │    │    ├── concat
                │                   │              │    │    │    ├── concat
                │                   │              │    │    │    │    ├── const: ''
                │                   │              │    │    │    │    └── coalesce
                │                   │              │    │    │    │         ├── cast: STRING
                │                   │              │    │    │    │         │    └── variable: x:5
                │                   │              │    │    │    │         └── const: '<NULL>'
                │                   │              │    │    │    └── const: ' '
                │                   │              │    │    └── coalesce
                │                   │              │    │         ├── cast: STRING
                │                   │              │    │         │    └── variable: y:6
                │                   │              │    │         └── const: '<NULL>'
                │                   │              │    └── const: ''
                │                   │              ├── const: ''
                │                   │              ├── const: ''
                │                   │              └── const: '00000'
                │                   └── project
                │                        ├── columns: "_stmt_raise_6":26
                │                        ├── barrier
                │                        │    ├── columns: x:18 y:19 z:20!null
                │                        │    └── project
                │                        │         ├── columns: z:20!null x:18 y:19
                │                        │         ├── project
                │                        │         │    ├── columns: y:19 z:17!null x:18
                │                        │         │    ├── project
                │                        │         │    │    ├── columns: x:18 z:17!null
                │                        │         │    │    ├── project
                │                        │         │    │    │    ├── columns: z:17!null
                │                        │         │    │    │    ├── values
                │                        │         │    │    │    │    └── tuple
                │                        │         │    │    │    └── projections
                │                        │         │    │    │         └── const: 100 [as=z:17]
                │                        │         │    │    └── projections
                │                        │         │    │         └── plus [as=x:18]
                │                        │         │    │              ├── variable: x:5
                │                        │         │    │              └── const: 1
                │                        │         │    └── projections
                │                        │         │         └── plus [as=y:19]
                │                        │         │              ├── variable: y:6
                │                        │         │              └── const: 1
                │                        │         └── projections
                │                        │              └── plus [as=z:20]
                │                        │                   ├── variable: z:17
                │                        │                   └── const: 1
                │                        └── projections
                │                             └── udf: _stmt_raise_6 [as="_stmt_raise_6":26]
                │                                  ├── tail-call
                │                                  ├── args
                │                                  │    ├── variable: x:18
                │                                  │    ├── variable: y:19
                │                                  │    └── variable: z:20
                │                                  ├── params: x:21 y:22 z:23
                │                                  └── body
                │                                       ├── project
                │                                       │    ├── columns: stmt_raise_7:24
                │                                       │    ├── values
                │                                       │    │    └── tuple
                │                                       │    └── projections
                │                                       │         └── function: crdb_internal.plpgsql_raise [as=stmt_raise_7:24]
                │                                       │              ├── const: 'NOTICE'
                │                                       │              ├── concat
                │                                       │              │    ├── concat
                │                                       │              │    │    ├── concat
                │                                       │              │    │    │    ├── concat
                │                                       │              │    │    │    │    ├── concat
                │                                       │              │    │    │    │    │    ├── concat
                │                                       │              │    │    │    │    │    │    ├── const: ''
                │                                       │              │    │    │    │    │    │    └── coalesce
                │                                       │              │    │    │    │    │    │         ├── cast: STRING
                │                                       │              │    │    │    │    │    │         │    └── variable: x:21
                │                                       │              │    │    │    │    │    │         └── const: '<NULL>'
                │                                       │              │    │    │    │    │    └── const: ' '
                │                                       │              │    │    │    │    └── coalesce
                │                                       │              │    │    │    │         ├── cast: STRING
                │                                       │              │    │    │    │         │    └── variable: y:22
                │                                       │              │    │    │    │         └── const: '<NULL>'
                │                                       │              │    │    │    └── const: ' '
                │                                       │              │    │    └── coalesce
                │                                       │              │    │         ├── cast: STRING
                │                                       │              │    │         │    └── variable: z:23
                │                                       │              │    │         └── const: '<NULL>'
                │                                       │              │    └── const: ''
                │                                       │              ├── const: ''
                │                                       │              ├── const: ''
                │                                       │              └── const: '00000'
                │                                       └── project
                │                                            ├── columns: post_nested_block_3:25
                │                                            ├── values
                │                                            │    └── tuple
                │                                            └── projections
                │                                                 └── udf: post_nested_block_3 [as=post_nested_block_3:25]
                │                                                      ├── tail-call
                │                                                      ├── args
                │                                                      │    ├── variable: x:21
                │                                                      │    └── variable: y:22
                │                                                      ├── params: x:8 y:9
                │                                                      └── body
                │                                                           └── project
                │                                                                ├── columns: "_stmt_raise_4":16
                │                                                                ├── barrier
                │                                                                │    ├── columns: x:10 y:11
                │                                                                │    └── project
                │                                                                │         ├── columns: y:11 x:10
                │                                                                │         ├── project
                │                                                                │         │    ├── columns: x:10
                │                                                                │         │    ├── values
                │                                                                │         │    │    └── tuple
                │                                                                │         │    └── projections
                │                                                                │         │         └── plus [as=x:10]
                │                                                                │         │              ├── variable: x:8
                │                                                                │         │              └── const: 1
                │                                                                │         └── projections
                │                                                                │              └── plus [as=y:11]
                │                                                                │                   ├── variable: y:9
                │                                                                │                   └── const: 1
                │                                                                └── projections
                │                                                                     └── udf: _stmt_raise_4 [as="_stmt_raise_4":16]
                │                                                                          ├── tail-call
                │                                                                          ├── args
                │                                                                          │    ├── variable: x:10
                │                                                                          │    └── variable: y:11
                │                                                                          ├── params: x:12 y:13
                │                                                                          └── body
                │                                                                               ├── project
                │                                                                               │    ├── columns: stmt_raise_5:14
                │                                                                               │    ├── values
                │                                                                               │    │    └── tuple
                │                                                                               │    └── projections
                │                                                                               │         └── function: crdb_internal.plpgsql_raise [as=stmt_raise_5:14]
                │                                                                               │              ├── const: 'NOTICE'
                │                                                                               │              ├── concat
                │                                                                               │              │    ├── concat
                │                                                                               │              │    │    ├── concat
                │                                                                               │              │    │    │    ├── concat
                │                                                                               │              │    │    │    │    ├── const: ''
                │                                                                               │              │    │    │    │    └── coalesce
                │                                                                               │              │    │    │    │         ├── cast: STRING
                │                                                                               │              │    │    │    │         │    └── variable: x:12
                │                                                                               │              │    │    │    │         └── const: '<NULL>'
                │                                                                               │              │    │    │    └── const: ' '
                │                                                                               │              │    │    └── coalesce
                │                                                                               │              │    │         ├── cast: STRING
                │                                                                               │              │    │         │    └── variable: y:13
                │                                                                               │              │    │         └── const: '<NULL>'
                │                                                                               │              │    └── const: ''
                │                                                                               │              ├── const: ''
                │                                                                               │              ├── const: ''
                │                                                                               │              └── const: '00000'
                │                                                                               └── project
                │                                                                                    ├── columns: "_implicit_return":15
                │                                                                                    ├── values
                │                                                                                    │    └── tuple
                │                                                                                    └── projections
                │                                                                                         └── cast: VOID [as="_implicit_return":15]
                │                                                                                              └── null
                └── const: 1

# Nested blocks with an exception handler. Note that the exception handler
# returns control to the outer block, so that the variable assignment is
# visible in the outer block.
exec-ddl
CREATE OR REPLACE PROCEDURE p() AS $$
  DECLARE
    x INT := 0;
  BEGIN
    RAISE NOTICE '%', x;
    BEGIN
      SELECT 1 // 0;
    EXCEPTION
      WHEN division_by_zero THEN
        x := 100;
    END;
    RAISE NOTICE '%', x;
  END
$$ LANGUAGE PLpgSQL;
----

build format=show-scalars
CALL p()
----
call
 └── procedure: p
      └── body
           └── limit
                ├── columns: "_stmt_raise_1":18
                ├── project
                │    ├── columns: "_stmt_raise_1":18
                │    ├── barrier
                │    │    ├── columns: x:1!null
                │    │    └── project
                │    │         ├── columns: x:1!null
                │    │         ├── values
                │    │         │    └── tuple
                │    │         └── projections
                │    │              └── const: 0 [as=x:1]
                │    └── projections
                │         └── udf: _stmt_raise_1 [as="_stmt_raise_1":18]
                │              ├── args
                │              │    └── variable: x:1
                │              ├── params: x:2
                │              └── body
                │                   ├── project
                │                   │    ├── columns: stmt_raise_2:3
                │                   │    ├── values
                │                   │    │    └── tuple
                │                   │    └── projections
                │                   │         └── function: crdb_internal.plpgsql_raise [as=stmt_raise_2:3]
                │                   │              ├── const: 'NOTICE'
                │                   │              ├── concat
                │                   │              │    ├── concat
                │                   │              │    │    ├── const: ''
                │                   │              │    │    └── coalesce
                │                   │              │    │         ├── cast: STRING
                │                   │              │    │         │    └── variable: x:2
                │                   │              │    │         └── const: '<NULL>'
                │                   │              │    └── const: ''
                │                   │              ├── const: ''
                │                   │              ├── const: ''
                │                   │              └── const: '00000'
                │                   └── project
                │                        ├── columns: nested_block_7:17
                │                        ├── values
                │                        │    └── tuple
                │                        └── projections
                │                             └── udf: nested_block_7 [as=nested_block_7:17]
                │                                  ├── tail-call
                │                                  ├── args
                │                                  │    └── variable: x:2
                │                                  ├── params: x:12
                │                                  ├── body
                │                                  │    └── project
                │                                  │         ├── columns: "_stmt_exec_8":16
                │                                  │         ├── values
                │                                  │         │    └── tuple
                │                                  │         └── projections
                │                                  │              └── udf: _stmt_exec_8 [as="_stmt_exec_8":16]
                │                                  │                   ├── tail-call
                │                                  │                   ├── args
                │                                  │                   │    └── variable: x:12
                │                                  │                   ├── params: x:13
                │                                  │                   └── body
                │                                  │                        ├── project
                │                                  │                        │    ├── columns: "?column?":14!null
                │                                  │                        │    ├── values
                │                                  │                        │    │    └── tuple
                │                                  │                        │    └── projections
                │                                  │                        │         └── floor-div [as="?column?":14]
                │                                  │                        │              ├── const: 1
                │                                  │                        │              └── const: 0
                │                                  │                        └── project
                │                                  │                             ├── columns: post_nested_block_3:15
                │                                  │                             ├── values
                │                                  │                             │    └── tuple
                │                                  │                             └── projections
                │                                  │                                  └── udf: post_nested_block_3 [as=post_nested_block_3:15]
                │                                  │                                       ├── tail-call
                │                                  │                                       ├── args
                │                                  │                                       │    └── variable: x:13
                │                                  │                                       ├── params: x:4
                │                                  │                                       └── body
                │                                  │                                            └── project
                │                                  │                                                 ├── columns: "_stmt_raise_4":8
                │                                  │                                                 ├── values
                │                                  │                                                 │    └── tuple
                │                                  │                                                 └── projections
                │                                  │                                                      └── udf: _stmt_raise_4 [as="_stmt_raise_4":8]
                │                                  │                                                           ├── tail-call
                │                                  │                                                           ├── args
                │                                  │                                                           │    └── variable: x:4
                │                                  │                                                           ├── params: x:5
                │                                  │                                                           └── body
                │                                  │                                                                ├── project
                │                                  │                                                                │    ├── columns: stmt_raise_5:6
                │                                  │                                                                │    ├── values
                │                                  │                                                                │    │    └── tuple
                │                                  │                                                                │    └── projections
                │                                  │                                                                │         └── function: crdb_internal.plpgsql_raise [as=stmt_raise_5:6]
                │                                  │                                                                │              ├── const: 'NOTICE'
                │                                  │                                                                │              ├── concat
                │                                  │                                                                │              │    ├── concat
                │                                  │                                                                │              │    │    ├── const: ''
                │                                  │                                                                │              │    │    └── coalesce
                │                                  │                                                                │              │    │         ├── cast: STRING
                │                                  │                                                                │              │    │         │    └── variable: x:5
                │                                  │                                                                │              │    │         └── const: '<NULL>'
                │                                  │                                                                │              │    └── const: ''
                │                                  │                                                                │              ├── const: ''
                │                                  │                                                                │              ├── const: ''
                │                                  │                                                                │              └── const: '00000'
                │                                  │                                                                └── project
                │                                  │                                                                     ├── columns: "_implicit_return":7
                │                                  │                                                                     ├── values
                │                                  │                                                                     │    └── tuple
                │                                  │                                                                     └── projections
                │                                  │                                                                          └── cast: VOID [as="_implicit_return":7]
                │                                  │                                                                               └── null
                │                                  └── exception-handler
                │                                       └── SQLSTATE '22012'
                │                                            └── project
                │                                                 ├── columns: post_nested_block_3:11
                │                                                 ├── barrier
                │                                                 │    ├── columns: x:10!null
                │                                                 │    └── project
                │                                                 │         ├── columns: x:10!null
                │                                                 │         ├── values
                │                                                 │         │    └── tuple
                │                                                 │         └── projections
                │                                                 │              └── const: 100 [as=x:10]
                │                                                 └── projections
                │                                                      └── udf: post_nested_block_3 [as=post_nested_block_3:11]
                │                                                           ├── args
                │                                                           │    └── variable: x:10
                │                                                           ├── params: x:4
                │                                                           └── body
                │                                                                └── project
                │                                                                     ├── columns: "_stmt_raise_4":8
                │                                                                     ├── values
                │                                                                     │    └── tuple
                │                                                                     └── projections
                │                                                                          └── udf: _stmt_raise_4 [as="_stmt_raise_4":8]
                │                                                                               ├── tail-call
                │                                                                               ├── args
                │                                                                               │    └── variable: x:4
                │                                                                               ├── params: x:5
                │                                                                               └── body
                │                                                                                    ├── project
                │                                                                                    │    ├── columns: stmt_raise_5:6
                │                                                                                    │    ├── values
                │                                                                                    │    │    └── tuple
                │                                                                                    │    └── projections
                │                                                                                    │         └── function: crdb_internal.plpgsql_raise [as=stmt_raise_5:6]
                │                                                                                    │              ├── const: 'NOTICE'
                │                                                                                    │              ├── concat
                │                                                                                    │              │    ├── concat
                │                                                                                    │              │    │    ├── const: ''
                │                                                                                    │              │    │    └── coalesce
                │                                                                                    │              │    │         ├── cast: STRING
                │                                                                                    │              │    │         │    └── variable: x:5
                │                                                                                    │              │    │         └── const: '<NULL>'
                │                                                                                    │              │    └── const: ''
                │                                                                                    │              ├── const: ''
                │                                                                                    │              ├── const: ''
                │                                                                                    │              └── const: '00000'
                │                                                                                    └── project
                │                                                                                         ├── columns: "_implicit_return":7
                │                                                                                         ├── values
                │                                                                                         │    └── tuple
                │                                                                                         └── projections
                │                                                                                              └── cast: VOID [as="_implicit_return":7]
                │                                                                                                   └── null
                └── const: 1

# Build an implicit RETURN statement for a routine with OUT params.
exec-ddl
CREATE PROCEDURE p_out(OUT x INT, OUT y INT) AS $$
  BEGIN
    x := 1;
    IF x > 0 THEN
      y := 2;
    END IF;
  END
$$ LANGUAGE PLpgSQL;
----

build format=show-scalars
CALL p_out(NULL, NULL);
----
call
 ├── columns: x:1 y:2
 └── procedure: p_out
      └── body
           └── limit
                ├── columns: stmt_if_2:12
                ├── project
                │    ├── columns: stmt_if_2:12
                │    ├── project
                │    │    ├── columns: x:5!null y:4
                │    │    ├── project
                │    │    │    ├── columns: y:4 x:3
                │    │    │    ├── project
                │    │    │    │    ├── columns: x:3
                │    │    │    │    ├── values
                │    │    │    │    │    └── tuple
                │    │    │    │    └── projections
                │    │    │    │         └── cast: INT8 [as=x:3]
                │    │    │    │              └── null
                │    │    │    └── projections
                │    │    │         └── cast: INT8 [as=y:4]
                │    │    │              └── null
                │    │    └── projections
                │    │         └── const: 1 [as=x:5]
                │    └── projections
                │         └── case [as=stmt_if_2:12]
                │              ├── true
                │              ├── when
                │              │    ├── gt
                │              │    │    ├── variable: x:5
                │              │    │    └── const: 0
                │              │    └── subquery
                │              │         └── project
                │              │              ├── columns: stmt_if_1:10
                │              │              ├── project
                │              │              │    ├── columns: y:9!null
                │              │              │    ├── values
                │              │              │    │    └── tuple
                │              │              │    └── projections
                │              │              │         └── const: 2 [as=y:9]
                │              │              └── projections
                │              │                   └── udf: stmt_if_1 [as=stmt_if_1:10]
                │              │                        ├── tail-call
                │              │                        ├── args
                │              │                        │    ├── variable: x:5
                │              │                        │    └── variable: y:9
                │              │                        ├── params: x:6 y:7
                │              │                        └── body
                │              │                             └── project
                │              │                                  ├── columns: "_implicit_return":8
                │              │                                  ├── values
                │              │                                  │    └── tuple
                │              │                                  └── projections
                │              │                                       └── cast: RECORD [as="_implicit_return":8]
                │              │                                            └── tuple
                │              │                                                 ├── variable: x:6
                │              │                                                 └── variable: y:7
                │              └── subquery
                │                   └── project
                │                        ├── columns: stmt_if_1:11
                │                        ├── values
                │                        │    └── tuple
                │                        └── projections
                │                             └── udf: stmt_if_1 [as=stmt_if_1:11]
                │                                  ├── tail-call
                │                                  ├── args
                │                                  │    ├── variable: x:5
                │                                  │    └── variable: y:4
                │                                  ├── params: x:6 y:7
                │                                  └── body
                │                                       └── project
                │                                            ├── columns: "_implicit_return":8
                │                                            ├── values
                │                                            │    └── tuple
                │                                            └── projections
                │                                                 └── cast: RECORD [as="_implicit_return":8]
                │                                                      └── tuple
                │                                                           ├── variable: x:6
                │                                                           └── variable: y:7
                └── const: 1
