-
Notifications
You must be signed in to change notification settings - Fork 29
fix: function dump default #126
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
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "issue_125_function_default", | ||
| "description": "Test case for function parameter defaults being lost when dumping (GitHub issue #125)", | ||
| "source": "https://github.com/pgschema/pgschema/issues/125", | ||
| "notes": [ | ||
| "Tests that function parameter default values are correctly preserved when dumping", | ||
| "Reproduces the bug where defaults like 'DEFAULT TRUE' and 'DEFAULT NULL' are lost", | ||
| "Tests both simple IN parameters with defaults and functions with OUT/INOUT parameters" | ||
| ] | ||
| } |
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,82 @@ | ||
| -- | ||
| -- PostgreSQL database dump | ||
| -- | ||
|
|
||
| SET statement_timeout = 0; | ||
| SET lock_timeout = 0; | ||
| SET client_encoding = 'UTF8'; | ||
| SET standard_conforming_strings = on; | ||
| SET check_function_bodies = false; | ||
| SET client_min_messages = warning; | ||
| SET row_security = off; | ||
|
|
||
| -- | ||
| -- Name: test_simple_defaults(integer, text, boolean, numeric, timestamp without time zone); Type: FUNCTION; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE FUNCTION public.test_simple_defaults(param1 integer DEFAULT 42, param2 text DEFAULT 'hello world'::text, param3 boolean DEFAULT true, param4 numeric DEFAULT 3.14, param5 timestamp without time zone DEFAULT CURRENT_TIMESTAMP) RETURNS text | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| BEGIN | ||
| RETURN 'Params: ' || param1 || ', ' || param2 || ', ' || param3 || ', ' || param4 || ', ' || param5; | ||
| END; | ||
| $$; | ||
|
|
||
| -- | ||
| -- Name: test_mixed_params(boolean, text, integer); Type: FUNCTION; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE FUNCTION public.test_mixed_params(raise_on_error boolean DEFAULT true, p_schema_override text DEFAULT NULL::text, max_retries integer DEFAULT 3, OUT success boolean, OUT message text) RETURNS record | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| BEGIN | ||
| success := NOT raise_on_error; | ||
| message := 'Schema: ' || COALESCE(p_schema_override, 'default') || ', Retries: ' || max_retries; | ||
| END; | ||
| $$; | ||
|
|
||
| -- | ||
| -- Name: test_inout_params(integer, numeric, numeric); Type: FUNCTION; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE FUNCTION public.test_inout_params(value integer DEFAULT 100, INOUT multiplier numeric DEFAULT 1.5, INOUT result numeric DEFAULT NULL::numeric) RETURNS record | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| BEGIN | ||
| result := value * multiplier; | ||
| multiplier := multiplier * 2; | ||
| END; | ||
| $$; | ||
|
|
||
| -- | ||
| -- Name: test_complex_defaults(integer[], jsonb, int4range, integer); Type: FUNCTION; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE FUNCTION public.test_complex_defaults(arr integer[] DEFAULT ARRAY[1, 2, 3], json_data jsonb DEFAULT '{"key": "value"}'::jsonb, range_val int4range DEFAULT '[1,10)'::int4range, expr_default integer DEFAULT 40) RETURNS jsonb | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| BEGIN | ||
| RETURN jsonb_build_object( | ||
| 'arr', arr, | ||
| 'json', json_data, | ||
| 'range', range_val::text, | ||
| 'expr', expr_default | ||
| ); | ||
| END; | ||
| $$; | ||
|
|
||
| -- | ||
| -- Name: test_variadic_defaults(text, integer[]); Type: FUNCTION; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE FUNCTION public.test_variadic_defaults(prefix text DEFAULT 'Result:'::text, VARIADIC numbers integer[] DEFAULT ARRAY[]::integer[]) RETURNS text | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| BEGIN | ||
| RETURN prefix || ' ' || array_to_string(numbers, ', '); | ||
| END; | ||
| $$; | ||
|
|
||
| -- | ||
| -- PostgreSQL database dump complete | ||
| -- |
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,114 @@ | ||||||
| -- | ||||||
| -- pgschema database dump | ||||||
| -- | ||||||
|
|
||||||
| -- Dumped from database version PostgreSQL 17.5 | ||||||
| -- Dumped by pgschema version 1.4.0 | ||||||
|
|
||||||
|
|
||||||
| -- | ||||||
| -- Name: test_complex_defaults; Type: FUNCTION; Schema: -; Owner: - | ||||||
| -- | ||||||
|
|
||||||
| CREATE OR REPLACE FUNCTION test_complex_defaults( | ||||||
| arr integer[] DEFAULT ARRAY[1, 2, 3], | ||||||
| json_data jsonb DEFAULT '{"key": "value"}', | ||||||
| range_val int4range DEFAULT '[1,10)', | ||||||
| expr_default integer DEFAULT 40 | ||||||
| ) | ||||||
| RETURNS jsonb | ||||||
| LANGUAGE plpgsql | ||||||
| SECURITY INVOKER | ||||||
| VOLATILE | ||||||
| AS $$ | ||||||
| BEGIN | ||||||
| RETURN jsonb_build_object( | ||||||
| 'arr', arr, | ||||||
| 'json', json_data, | ||||||
| 'range', range_val::text, | ||||||
| 'expr', expr_default | ||||||
| ); | ||||||
| END; | ||||||
| $$; | ||||||
|
|
||||||
| -- | ||||||
| -- Name: test_inout_params; Type: FUNCTION; Schema: -; Owner: - | ||||||
| -- | ||||||
|
|
||||||
| CREATE OR REPLACE FUNCTION test_inout_params( | ||||||
| value integer DEFAULT 100, | ||||||
| INOUT multiplier numeric DEFAULT 1.5, | ||||||
| INOUT result numeric DEFAULT NULL | ||||||
| ) | ||||||
| RETURNS record | ||||||
| LANGUAGE plpgsql | ||||||
| SECURITY INVOKER | ||||||
| VOLATILE | ||||||
| AS $$ | ||||||
| BEGIN | ||||||
| result := value * multiplier; | ||||||
| multiplier := multiplier * 2; | ||||||
| END; | ||||||
| $$; | ||||||
|
|
||||||
| -- | ||||||
| -- Name: test_mixed_params; Type: FUNCTION; Schema: -; Owner: - | ||||||
| -- | ||||||
|
|
||||||
| CREATE OR REPLACE FUNCTION test_mixed_params( | ||||||
| raise_on_error boolean DEFAULT true, | ||||||
| p_schema_override text DEFAULT NULL, | ||||||
|
||||||
| p_schema_override text DEFAULT NULL, | |
| p_schema_override text DEFAULT NULL::text, |
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.
The default value
DEFAULT NULLis missing the explicit type cast. According to pgdump.sql line 49, this should beDEFAULT NULL::numericto properly specify the typed null value.