Skip to content

sql: column does not exists error for statement with alias inside UDF #104927

@mgartner

Description

@mgartner

Consider the table:

CREATE TABLE t (
  i INT,
  s STRING
);

INSERT INTO t VALUES (1, 'foo');

Running this statement:

SELECT json_agg(r) FROM (
  SELECT i, s
  FROM t
) AS r;

Produces:

         json_agg
--------------------------
  [{"i": 1, "s": "foo"}]
(1 row)

Running the same statement inside a UDF:

CREATE FUNCTION f() RETURNS TEXT LANGUAGE SQL AS $$
  SELECT json_agg(r) FROM (
    SELECT i, s
    FROM t
  ) AS r
$$;

SELECT f();

Produces an error:

ERROR: column "r" does not exist
SQLSTATE: 42703

Jira issue: CRDB-28779

Metadata

Metadata

Assignees

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-queriesSQL Queries Teamdocs-known-limitation

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions