-
Notifications
You must be signed in to change notification settings - Fork 57
fix: defer functions whose signature uses a deferred table's row type (#545) #546
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b26e0ff
fix: defer functions whose signature uses a deferred table's row type…
tianzhou 7f8b9a6
fix: emit functions referencing last-batch tables after that batch
tianzhou 055f9d0
fix: detect deferred-table references in TABLE(...) return types
tianzhou f3160a1
test: merge RETURNS TABLE case into issue_545 last-batch fixture
tianzhou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
testdata/diff/dependency/issue_545_signature_ref_table_after_domain/diff.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| CREATE TABLE IF NOT EXISTS base ( | ||
|
|
||
| ); | ||
|
|
||
| CREATE DOMAIN d AS base; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS uses ( | ||
| dcol d | ||
| ); | ||
|
|
||
| CREATE OR REPLACE FUNCTION uses_check( | ||
| r uses | ||
| ) | ||
| RETURNS boolean | ||
| LANGUAGE plpgsql | ||
| VOLATILE | ||
| AS $$ | ||
| BEGIN | ||
| RETURN r.dcol IS NOT NULL; | ||
| END; | ||
| $$; | ||
|
|
||
| CREATE OR REPLACE FUNCTION uses_rows() | ||
| RETURNS TABLE(r uses) | ||
| LANGUAGE plpgsql | ||
| VOLATILE | ||
| AS $$ | ||
| BEGIN | ||
| RETURN; | ||
| END; | ||
| $$; |
27 changes: 27 additions & 0 deletions
27
testdata/diff/dependency/issue_545_signature_ref_table_after_domain/new.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| CREATE TABLE base (); | ||
|
|
||
| CREATE DOMAIN d AS base; | ||
|
|
||
| CREATE TABLE uses ( | ||
| dcol d | ||
| ); | ||
|
|
||
| -- Function signature references table "uses", which itself must be created | ||
| -- after domain d (whose base type is table base's row type). The function | ||
| -- must therefore come after the last table batch. | ||
| CREATE FUNCTION public.uses_check(r uses) | ||
| RETURNS boolean LANGUAGE plpgsql AS $$ | ||
| BEGIN | ||
| RETURN r.dcol IS NOT NULL; | ||
| END; | ||
| $$; | ||
|
|
||
| -- Depends on table "uses" only through the TABLE(...) output column type; | ||
| -- these columns are excluded from pg_get_function_arguments and only appear | ||
| -- in pg_get_function_result as "TABLE(r uses)". | ||
| CREATE FUNCTION public.uses_rows() | ||
| RETURNS TABLE(r uses) LANGUAGE plpgsql AS $$ | ||
| BEGIN | ||
| RETURN; | ||
| END; | ||
| $$; |
Empty file.
44 changes: 44 additions & 0 deletions
44
testdata/diff/dependency/issue_545_signature_ref_table_after_domain/plan.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "version": "1.0.0", | ||
| "pgschema_version": "1.12.3", | ||
| "created_at": "1970-01-01T00:00:00Z", | ||
| "source_fingerprint": { | ||
| "hash": "965b1131737c955e24c7f827c55bd78e4cb49a75adfd04229e0ba297376f5085" | ||
| }, | ||
| "groups": [ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "sql": "CREATE TABLE IF NOT EXISTS base (\n\n);", | ||
| "type": "table", | ||
| "operation": "create", | ||
| "path": "public.base" | ||
| }, | ||
| { | ||
| "sql": "CREATE DOMAIN d AS base;", | ||
| "type": "domain", | ||
| "operation": "create", | ||
| "path": "public.d" | ||
| }, | ||
| { | ||
| "sql": "CREATE TABLE IF NOT EXISTS uses (\n dcol d\n);", | ||
| "type": "table", | ||
| "operation": "create", | ||
| "path": "public.uses" | ||
| }, | ||
| { | ||
| "sql": "CREATE OR REPLACE FUNCTION uses_check(\n r uses\n)\nRETURNS boolean\nLANGUAGE plpgsql\nVOLATILE\nAS $$\nBEGIN\n RETURN r.dcol IS NOT NULL;\nEND;\n$$;", | ||
| "type": "function", | ||
| "operation": "create", | ||
| "path": "public.uses_check" | ||
| }, | ||
| { | ||
| "sql": "CREATE OR REPLACE FUNCTION uses_rows()\nRETURNS TABLE(r uses)\nLANGUAGE plpgsql\nVOLATILE\nAS $$\nBEGIN\n RETURN;\nEND;\n$$;", | ||
| "type": "function", | ||
| "operation": "create", | ||
| "path": "public.uses_rows" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and fixed in 055f9d0. Reproduced with a new test case (
dependency/issue_545_returns_table_ref): a function declaredRETURNS TABLE(r x)wherexis a deferred table was emitted before the table, since the output columns only appear inpg_get_function_resultasTABLE(r x)andextractBaseTypeNameleft that expression unparsed.functionSignatureReferencesRelationnow parses theTABLE(...)column list (paren- and quote-aware for types likenumeric(10,2)and quoted identifiers) and checks each output column type.