-
Notifications
You must be signed in to change notification settings - Fork 34
fix: handle empty search_path and preserve schema qualifiers in function bodies (#354) #357
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
+100
−3
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
12 changes: 12 additions & 0 deletions
12
testdata/diff/create_function/issue_354_empty_search_path/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,12 @@ | ||
| CREATE OR REPLACE FUNCTION create_hello( | ||
| p_title text | ||
| ) | ||
| RETURNS void | ||
| LANGUAGE plpgsql | ||
| VOLATILE | ||
| SET search_path = '' | ||
| AS $$ | ||
| BEGIN | ||
| INSERT INTO test (title) VALUES (p_title); | ||
| END; | ||
| $$; |
17 changes: 17 additions & 0 deletions
17
testdata/diff/create_function/issue_354_empty_search_path/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,17 @@ | ||
| CREATE TABLE public.test ( | ||
| id bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, | ||
| title text, | ||
| created_at timestamp with time zone DEFAULT now() NOT NULL, | ||
| CONSTRAINT test_pkey PRIMARY KEY (id) | ||
| ); | ||
|
|
||
| CREATE OR REPLACE FUNCTION create_hello(p_title text) | ||
| RETURNS void | ||
| LANGUAGE plpgsql | ||
| SECURITY INVOKER | ||
| SET search_path = '' | ||
| AS $$ | ||
| BEGIN | ||
| INSERT INTO public.test (title) VALUES (p_title); | ||
| END; | ||
| $$; |
6 changes: 6 additions & 0 deletions
6
testdata/diff/create_function/issue_354_empty_search_path/old.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,6 @@ | ||
| CREATE TABLE public.test ( | ||
| id bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, | ||
| title text, | ||
| created_at timestamp with time zone DEFAULT now() NOT NULL, | ||
| CONSTRAINT test_pkey PRIMARY KEY (id) | ||
| ); |
20 changes: 20 additions & 0 deletions
20
testdata/diff/create_function/issue_354_empty_search_path/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,20 @@ | ||
| { | ||
| "version": "1.0.0", | ||
| "pgschema_version": "1.7.4", | ||
| "created_at": "1970-01-01T00:00:00Z", | ||
| "source_fingerprint": { | ||
| "hash": "742d612cedabf2d80d87df6c7d9fac8911e008b29ef8e15d16a32d2edf43ddd9" | ||
| }, | ||
| "groups": [ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "sql": "CREATE OR REPLACE FUNCTION create_hello(\n p_title text\n)\nRETURNS void\nLANGUAGE plpgsql\nVOLATILE\nSET search_path = ''\nAS $$\nBEGIN\n INSERT INTO test (title) VALUES (p_title);\nEND;\n$$;", | ||
| "type": "function", | ||
| "operation": "create", | ||
| "path": "public.create_hello" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
12 changes: 12 additions & 0 deletions
12
testdata/diff/create_function/issue_354_empty_search_path/plan.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,12 @@ | ||
| CREATE OR REPLACE FUNCTION create_hello( | ||
| p_title text | ||
| ) | ||
| RETURNS void | ||
| LANGUAGE plpgsql | ||
| VOLATILE | ||
| SET search_path = '' | ||
| AS $$ | ||
| BEGIN | ||
| INSERT INTO test (title) VALUES (p_title); | ||
| END; | ||
| $$; |
23 changes: 23 additions & 0 deletions
23
testdata/diff/create_function/issue_354_empty_search_path/plan.txt
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,23 @@ | ||
| Plan: 1 to add. | ||
|
|
||
| Summary by type: | ||
| functions: 1 to add | ||
|
|
||
| Functions: | ||
| + create_hello | ||
|
|
||
| DDL to be executed: | ||
| -------------------------------------------------- | ||
|
|
||
| CREATE OR REPLACE FUNCTION create_hello( | ||
| p_title text | ||
| ) | ||
| RETURNS void | ||
| LANGUAGE plpgsql | ||
| VOLATILE | ||
| SET search_path = '' | ||
| AS $$ | ||
| BEGIN | ||
| INSERT INTO test (title) VALUES (p_title); | ||
| END; | ||
| $$; |
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.
Consider also covering partial
""in a composite pathThe current check only fires when the entire
SearchPathvalue equals""(i.e.,search_path=""was the only proconfig entry, representing a fully empty path). If PostgreSQL ever stores a composite value such aspg_catalog, ""— where the empty element appears alongside real schemas — the literal""in that string would fall through to theelsebranch and be rendered verbatim as a double-quoted identifier, rather than''.In practice this is very unlikely, but since the fix already has a comment explaining the proconfig format, it might be worth a brief note here that only the whole-value case is handled: