-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: column does not exists error for statement with alias inside UDF #104927
Copy link
Copy link
Closed
Labels
C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-queriesSQL Queries TeamSQL Queries Teamdocs-known-limitation
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-queriesSQL Queries TeamSQL Queries Teamdocs-known-limitation
Type
Projects
Status
Done