Versioning

Fork/mirror of https://gitlab.com/depesz/Versioning
git clone https://ccx.te2000.cz/git/Versioning
Log | Files | Refs | README | LICENSE

commit 70aa23721d69454371ff42807699b9b04cf7bc37
parent 2dbcdf94e93a68a6f273375408a92d42c69dd5a5
Author: Hubert depesz Lubaczewski <depesz@depesz.com>
Date:   Mon, 17 Feb 2020 16:54:21 +0100

Use default value for parameters of function

Previously (before 8.4!) to allow:
- select function(a)
- select function(a,b)
- select function(a,b,c)
we had to have 3 function definitions.

Now we can have single with 3 parameters and default values for b and c.

This makes code simpler and less repetitious.

Diffstat:
Minstall.versioning.sql | 11+----------
1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/install.versioning.sql b/install.versioning.sql @@ -23,7 +23,7 @@ COMMENT ON COLUMN _v.patches.applied_by IS 'Who applied this patch (PostgreSQL COMMENT ON COLUMN _v.patches.requires IS 'List of patches that are required for given patch.'; COMMENT ON COLUMN _v.patches.conflicts IS 'List of patches that conflict with given patch.'; -CREATE OR REPLACE FUNCTION _v.register_patch( IN in_patch_name TEXT, IN in_requirements TEXT[], in_conflicts TEXT[], OUT versioning INT4 ) RETURNS setof INT4 AS $$ +CREATE OR REPLACE FUNCTION _v.register_patch( IN in_patch_name TEXT, IN in_requirements TEXT[] DEFAULT NULL, in_conflicts TEXT[] DEFAULT NULL, OUT versioning INT4 ) RETURNS setof INT4 AS $$ DECLARE t_text TEXT; t_text_a TEXT[]; @@ -61,15 +61,6 @@ END; $$ language plpgsql; COMMENT ON FUNCTION _v.register_patch( TEXT, TEXT[], TEXT[] ) IS 'Function to register patches in database. Raises exception if there are conflicts, prerequisites are not installed or the migration has already been installed.'; -CREATE OR REPLACE FUNCTION _v.register_patch( TEXT, TEXT[] ) RETURNS setof INT4 AS $$ - SELECT _v.register_patch( $1, $2, NULL ); -$$ language sql; -COMMENT ON FUNCTION _v.register_patch( TEXT, TEXT[] ) IS 'Wrapper to allow registration of patches without conflicts.'; -CREATE OR REPLACE FUNCTION _v.register_patch( TEXT ) RETURNS setof INT4 AS $$ - SELECT _v.register_patch( $1, NULL, NULL ); -$$ language sql; -COMMENT ON FUNCTION _v.register_patch( TEXT ) IS 'Wrapper to allow registration of patches without requirements and conflicts.'; - CREATE OR REPLACE FUNCTION _v.unregister_patch( IN in_patch_name TEXT, OUT versioning INT4 ) RETURNS setof INT4 AS $$ DECLARE i INT4;