cockroachdb / cockroachdb/cockroach
stmtbundle: include all function dependencies in correct order
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
If I run the following query:
```
SELECT * FROM public.all_category_names();
```
It produces a bundle with the following schema:
```
CREATE DATABASE dvdrental;
USE dvdrental;
CREATE FUNCTION public.all_category_names()
RETURNS SETOF STRING
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE plpgsql
SECURITY INVOKER
AS $$
DECLARE
cur CURSOR FOR SELECT name FROM dvdrental.public.category ORDER BY name;
cat_name STRING;
BEGIN
OPEN cur;
LOOP
FETCH 1 FROM cur INTO cat_name;
IF cat_name IS NULL THEN
EXIT;
END IF;
RETURN NEXT cat_name;
END LOOP;
CLOSE cur;
END;
$$;
USE dvdrental;
CREATE TABLE public.category (
category_id INT4 NOT NULL DEFAULT nextval('public.category_category_id_seq'::REGCLASS),
name VARCHAR(25) NOT NULL,
last_update TIMESTAMP NOT NULL DEFAULT now():::TIMESTAMP,
CONSTRAINT category_pkey PRIMARY KEY (category_id ASC)
);
```
There are a couple problems here:
1. `public.category` is created *after* the function, so attempting to recreate the bundle returns the error `ERROR: relation "dvdrental.public.category" does not exist`.
2. Even if I move the table definition up, the sequence definition is missing.
Jira issue: CRDB-50651
Contributor guide
Assessment
This issue has not been assessed yet.