cockroachdb / cockroachdb/cockroach

sql: track UPDATE SET column dependencies in UDFs and SPs

Open
#120,836 0 comments 0 reactions 0 assignees View on GitHub
C-bug T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Related to #102771.

We don't currently track UDF and SP dependencies on `SET` column in `UPDATE` statements in the routine body. This allows these columns to be renamed or dropped, which breaks the routine. For example:

```sql
CREATE TABLE t (
a INT PRIMARY KEY,
b INT
);

CREATE FUNCTION up() RETURNS VOID LANGUAGE SQL AS $$
UPDATE t SET b = 11 WHERE a = 1
$$;

-- This should fail, but it succeeds.
ALTER TABLE t RENAME COLUMN b TO b2;

-- Now, this fails.
SELECT up();
-- ERROR: column "b" does not exist
-- SQLSTATE: 42703
```

Jira issue: CRDB-36895

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.