Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: CREATE AS [SHOW CREATE FUNCTION] job fails #106268

Closed
ecwall opened this issue Jul 6, 2023 · 0 comments · Fixed by #107567
Closed

sql: CREATE AS [SHOW CREATE FUNCTION] job fails #106268

ecwall opened this issue Jul 6, 2023 · 0 comments · Fixed by #107567
Assignees
Labels
A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. db-cy-23 T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@ecwall
Copy link
Contributor

ecwall commented Jul 6, 2023

Running

CREATE FUNCTION fn(i int) RETURNS INT AS 'SELECT i' LANGUAGE SQL;
CREATE TABLE t AS SELECT * FROM [SHOW CREATE FUNCTION fn];

or

CREATE FUNCTION fn(i int) RETURNS INT AS 'SELECT i' LANGUAGE SQL;
CREATE MATERIALIZED VIEW v AS SELECT * FROM [SHOW CREATE FUNCTION fn];

results in a job failure (error message is slightly different for CREATE MATERIALIZED VIEW):

SELECT job_id, status, error, description 
FROM [SHOW JOBS] 
WHERE job_type IN ('SCHEMA CHANGE', 'NEW SCHEMA CHANGE')
AND status != 'succeeded''

880081200324935681, failed, unknown function: fn(): function undefined, CREATE TABLE defaultdb.public.t (function_name STRING, create_statement STRING) AS SELECT * FROM [SHOW CREATE FUNCTION fn]

Jira issue: CRDB-29473

Epic CRDB-27601

@ecwall ecwall added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-schema-changes T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Jul 6, 2023
@ecwall ecwall self-assigned this Jul 6, 2023
@ecwall ecwall removed their assignment Jul 6, 2023
@ecwall ecwall self-assigned this Jul 18, 2023
craig bot pushed a commit that referenced this issue Aug 2, 2023
107567: sql: fix CREATE AS [SHOW CREATE FUNCTION] job failure r=rafiss a=ecwall

Fixes #106268

Previously `CREATE TABLE AS`/`CREATE MATERIALIZED VIEW AS` sourcing from `SHOW CREATE FUNCTION <function>` generated a failing schema change job with a `unknown function: f(): function undefined` error because the job runs in the system database and functions cannot be referenced cross database.

This PR fixes this by using the original user session (which includes the database) in the schema change job.

Release note (bug fix): Fixes the schema changer job when CREATE AS sources from SHOW CREATE FUNCTION:
CREATE TABLE t AS SELECT * FROM [SHOW CREATE FUNCTION f];

Co-authored-by: Evan Wall <[email protected]>
@craig craig bot closed this as completed in 0695f6a Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. db-cy-23 T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant