Views that call functions are not ordered after those functions
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
Research direction
Start with GetViews and view_sql_generator.go, then inspect the View struct and the existing TableDependencies flow. Use the supplied function-and-view reproducer to verify dependency discovery and ordering. Done means the function is created before the view in the generated plan, without the current PostgreSQL error.
Written by the indexing model from the issue text.
Description
Views that call functions are not ordered after those functions
pg-schema-diff version
v1.0.5
Problem
A view definition can call a function:
CREATE FUNCTION fn_compute(id integer) RETURNS TABLE(result text) ...;
CREATE VIEW v_computed AS SELECT * FROM fn_compute(42);
pg-schema-diff does not track this dependency. The view may be created before the function, causing:
ERROR: function fn_compute(integer) does not exist (SQLSTATE 42883)
Root cause
The view vertex generator (view_sql_generator.go) only wires dependencies on tables (via TableDependencies). It has no awareness of function dependencies.
PostgreSQL does track view→function dependencies in pg_depend (via the view's rewrite rule), so the information is available:
SELECT pg_proc.proname, proc_ns.nspname,
pg_catalog.pg_get_function_identity_arguments(pg_proc.oid)
FROM pg_catalog.pg_depend AS d
JOIN pg_catalog.pg_rewrite AS r ON d.objid = r.oid AND r.ev_class = <view_oid>
JOIN pg_catalog.pg_depend AS d2 ON r.oid = d2.objid
JOIN pg_catalog.pg_proc ON d2.refobjid = pg_proc.oid AND d2.refclassid = 'pg_proc'::REGCLASS
JOIN pg_catalog.pg_namespace AS proc_ns ON pg_proc.pronamespace = proc_ns.oid
WHERE d.refobjid = <view_oid> AND d2.deptype = 'n'
AND proc_ns.nspname NOT IN ('pg_catalog', 'information_schema');
Suggested fix
- Add a
function_dependenciescolumn toGetViews(similar query to above) - Add
DependsOnFunctions []SchemaQualifiedNameto theViewstruct - In
view_sql_generator.goAdd(), wire:mustRun(addVertexId).after(buildFunctionVertexId(f, diffTypeAddAlter))
Reproducer
CREATE FUNCTION public.fn_helper() RETURNS TABLE(x int) LANGUAGE sql AS $$ SELECT 1; $$;
CREATE VIEW public.v_uses_fn AS SELECT * FROM public.fn_helper();
Plan from empty → target: view is ordered before function → apply fails.
Related
- #248 (function dependency ordering)
- Dominant language
- Go
- Stars
- 884
- Forks
- 82
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stripe/pg-schema-diff
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 76/100
stripe/pg-schema-diff#302 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
stripe/pg-schema-diff#283 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
stripe/pg-schema-diff#301 ·
-
Is the repo active? Open
Difficulty 1/5 Under an hour Newbie friendliness 15/100
stripe/pg-schema-diff#289 · 7 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
stripe/pg-schema-diff#282 ·
All issues in stripe/pg-schema-diff
Similar issues
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
blinklabs-io/bursa#904 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 comments ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100