Permalink
Browse files

Replaced overloaded functions with functions using DEFAULT values for…

… input parameters.
  • Loading branch information...
leehach committed Jun 7, 2012
1 parent 9a1906e commit 4b4e6db51e9b22c763e4b63dba8e21aa6de67c2e
View
@@ -110,9 +110,9 @@ The data scripts from the last section were created programmatically using sever
The meta-scripts are set up to run in the public schema, so that they can be called without qualification. If you prefer to keep these functions segregated in their own schema (e.g., census), you will later have to set the appropriate search_path or call them using a schema-qualified name (e.g. census.sql_import_geoheader()).
-In general, the order in which these scripts are run is not that important. Some of the user functions do refer to other user functions, but Postgres will create the function regardless and won't throw an error until the function with the dependecy is called. They are separated into these six files of related functions primarily for bookkeeping purposes. Only one of the last three (Data Store) scripts needs to be run. Running all three is harmless, as they merely create the functions which will create the data stores.
+In general, the order in which these scripts are run is not that important. Some of the user functions do refer to other user functions, but Postgres will create the function regardless and won't throw an error until the function with the dependecy is called. They are separated into these six files of related functions primarily for bookkeeping purposes. Only one of the Data Store scripts needs to be run (i.e., one of the last three scripts). Running all three is harmless, as they merely create the functions which will create the data stores.
-The actual functions and support tables are documented in this secion's subsections. In the function definition, brackets ([]) indicate optional parameters. For most of the following scripts, all parameters are optional. However, in order to specify a parameter, all earlier parameters must be explicitly given, even if the default value is desired.
+The actual functions and support tables are documented in this section's subsections. In the function definition, brackets ([]) indicate optional parameters. For most of the following scripts, all parameters are optional. However, in order to specify a parameter, all earlier parameters must be explicitly given, even if the default value is desired.
## Support Functions and Tables.sql
@@ -293,8 +293,8 @@ SELECT sql_geoheader_comments(TRUE);
SELECT sql_store_by_tables(TRUE);
SELECT sql_view_estimate_stored_by_tables(TRUE);
SELECT sql_view_moe_stored_by_tables(TRUE);
-SELECT sql_parse_tmp_geoheader(TRUE); Copies all data from tmp_geoheader to geoheader
-SELECT sql_insert_into_tables(TRUE); Copies all estimates and margins of error to sequence tables
+SELECT sql_parse_tmp_geoheader(TRUE); --Copies all data from tmp_geoheader to geoheader
+SELECT sql_insert_into_tables(TRUE); --Copies all estimates and margins of error to sequence tables
```
If using array-based or hstore-based data store, the last five functions will be different.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -5,7 +5,7 @@ SET search_path = public;
--CREATE DDL FOR STORAGE BY ARRAY COLUMNS
DROP FUNCTION IF EXISTS sql_store_by_array_columns(boolean);
-CREATE FUNCTION sql_store_by_array_columns(exec boolean) RETURNS text AS $function$
+CREATE FUNCTION sql_store_by_array_columns(exec boolean = FALSE) RETURNS text AS $function$
DECLARE
sql TEXT := '';
BEGIN
@@ -28,17 +28,6 @@ BEGIN
END;
$function$ LANGUAGE plpgsql;
-DROP FUNCTION IF EXISTS sql_store_by_array_columns();
-CREATE FUNCTION sql_store_by_array_columns() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_store_by_array_columns(FALSE) INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
-
/********************************************************************
Currently editing this function
*********************************************************************/
@@ -50,7 +39,7 @@ SELECT sql_parse_tmp_geoheader(ARRAY[TRUE], 'by_arrays');
This function adds data to columns with UPDATE statements.*/
DROP FUNCTION IF EXISTS sql_insert_into_array_columns(boolean);
-CREATE FUNCTION sql_insert_into_array_columns(exec boolean) RETURNS text AS $function$
+CREATE FUNCTION sql_insert_into_array_columns(exec boolean = FALSE) RETURNS text AS $function$
DECLARE
sql TEXT := '';
BEGIN
@@ -76,14 +65,3 @@ BEGIN
RETURN sql;
END;
$function$ LANGUAGE plpgsql;
-
-DROP FUNCTION IF EXISTS sql_insert_into_array_columns();
-CREATE FUNCTION sql_insert_into_array_columns() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_insert_into_array_columns(FALSE) INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
@@ -2,7 +2,7 @@
--CREATE DDL FOR STORAGE BY SEQUENCE
DROP FUNCTION IF EXISTS sql_store_by_tables(boolean);
-CREATE FUNCTION sql_store_by_tables(exec boolean) RETURNS text AS $function$
+CREATE FUNCTION sql_store_by_tables(exec boolean = FALSE) RETURNS text AS $function$
DECLARE
sql TEXT := '';
sql_estimate text;
@@ -44,18 +44,8 @@ BEGIN
END;
$function$ LANGUAGE plpgsql;
-DROP FUNCTION IF EXISTS sql_store_by_tables();
-CREATE FUNCTION sql_store_by_tables() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_store_by_tables(FALSE) INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
DROP FUNCTION IF EXISTS sql_view_estimate_stored_by_tables(boolean);
-CREATE FUNCTION sql_view_estimate_stored_by_tables(exec boolean) RETURNS text AS $function$
+CREATE FUNCTION sql_view_estimate_stored_by_tables(exec boolean = FALSE) RETURNS text AS $function$
DECLARE
sql TEXT := '';
BEGIN
@@ -89,22 +79,12 @@ BEGIN
END;
$function$ LANGUAGE plpgsql;
-DROP FUNCTION IF EXISTS sql_view_estimate_stored_by_tables();
-CREATE FUNCTION sql_view_estimate_stored_by_tables() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_view_estimate_stored_by_tables(FALSE) INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
/*Margin of error will rarely be used without estimate, so even though
they are stored in independent sequences, subject table views return estimates
as well as margins of error
*/
DROP FUNCTION IF EXISTS sql_view_moe_stored_by_tables(boolean);
-CREATE FUNCTION sql_view_moe_stored_by_tables(exec boolean) RETURNS text AS $function$
+CREATE FUNCTION sql_view_moe_stored_by_tables(exec boolean = FALSE) RETURNS text AS $function$
DECLARE
sql TEXT := '';
BEGIN
@@ -138,18 +118,8 @@ BEGIN
END;
$function$ LANGUAGE plpgsql;
-DROP FUNCTION IF EXISTS sql_view_moe_stored_by_tables();
-CREATE FUNCTION sql_view_moe_stored_by_tables() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_view_moe_stored_by_tables(FALSE) INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
DROP FUNCTION IF EXISTS sql_insert_into_tables(boolean, text);
-CREATE FUNCTION sql_insert_into_tables(exec boolean, actions text) RETURNS text AS $function$
+CREATE FUNCTION sql_insert_into_tables(exec boolean = FALSE, actions text = 'em') RETURNS text AS $function$
DECLARE
sql TEXT := '';
sql_estimate TEXT;
@@ -201,24 +171,4 @@ BEGIN
END;
$function$ LANGUAGE plpgsql;
-DROP FUNCTION IF EXISTS sql_insert_into_tables(boolean);
-CREATE FUNCTION sql_insert_into_tables(exec boolean) RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_insert_into_tables(exec, 'em') INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
-DROP FUNCTION IF EXISTS sql_insert_into_tables();
-CREATE FUNCTION sql_insert_into_tables() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_insert_into_tables(FALSE, 'em') INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
View
@@ -2,7 +2,7 @@
--CREATE SQL STATEMENT TO CREATE geoheader
DROP FUNCTION IF EXISTS sql_create_geoheader(boolean);
-CREATE FUNCTION sql_create_geoheader(exec boolean) RETURNS text AS $function$
+CREATE FUNCTION sql_create_geoheader(exec boolean = FALSE) RETURNS text AS $function$
DECLARE
sql TEXT;
BEGIN
@@ -31,19 +31,9 @@ BEGIN
END;
$function$ LANGUAGE plpgsql;
-DROP FUNCTION IF EXISTS sql_create_geoheader();
-CREATE FUNCTION sql_create_geoheader() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_create_geoheader(FALSE) INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
--ADD COMMENTS TO COLUMNS OF geoheader
DROP FUNCTION IF EXISTS sql_geoheader_comments(boolean);
-CREATE FUNCTION sql_geoheader_comments(exec boolean) RETURNS text AS $function$
+CREATE FUNCTION sql_geoheader_comments(exec boolean = FALSE) RETURNS text AS $function$
DECLARE
sql TEXT := '';
row RECORD;
@@ -58,20 +48,10 @@ BEGIN
END;
$function$ LANGUAGE plpgsql;
-DROP FUNCTION IF EXISTS sql_geoheader_comments();
-CREATE FUNCTION sql_geoheader_comments() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_geoheader_comments(FALSE) INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
--CREATE SQL STATEMENT TO PARSE tmp_geoheader INTO PERMANENT TABLE
--To Do: Allow target table to depend upon store_by method
DROP FUNCTION IF EXISTS sql_parse_tmp_geoheader(boolean, text);
-CREATE FUNCTION sql_parse_tmp_geoheader(exec boolean, target text) RETURNS text AS $function$
+CREATE FUNCTION sql_parse_tmp_geoheader(exec boolean = FALSE, target text = 'geoheader') RETURNS text AS $function$
DECLARE
sql TEXT := '';
row RECORD;
@@ -93,24 +73,3 @@ BEGIN
RETURN sql;
END;
$function$ LANGUAGE plpgsql;
-
-DROP FUNCTION IF EXISTS sql_parse_tmp_geoheader(boolean);
-CREATE FUNCTION sql_parse_tmp_geoheader(exec boolean) RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_parse_tmp_geoheader(exec, 'geoheader') INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
-DROP FUNCTION IF EXISTS sql_parse_tmp_geoheader();
-CREATE FUNCTION sql_parse_tmp_geoheader() RETURNS text AS $function$
-DECLARE
- sql TEXT := '';
-BEGIN
- SELECT sql_parse_tmp_geoheader(FALSE, 'geoheader') INTO sql;
- RETURN sql;
-END;
-$function$ LANGUAGE plpgsql;
-
Oops, something went wrong.

0 comments on commit 4b4e6db

Please sign in to comment.