Project

General

Profile

« Previous | Next » 

Revision 13495

schemas/util.sql: create_if_not_exists(): added relation param, which can be used to ensure that a standard exception is always generated if the relation exists, even if the table definition would be invalid (which generates a variety of exceptions)

View differences:

util.sql
1050 1050

  
1051 1051

  
1052 1052
--
1053
-- Name: create_if_not_exists(text); Type: FUNCTION; Schema: util; Owner: -
1053
-- Name: create_if_not_exists(text, text); Type: FUNCTION; Schema: util; Owner: -
1054 1054
--
1055 1055

  
1056
CREATE FUNCTION create_if_not_exists(sql text) RETURNS void
1057
    LANGUAGE plpgsql STRICT
1056
CREATE FUNCTION create_if_not_exists(sql text, relation text DEFAULT NULL::text) RETURNS void
1057
    LANGUAGE plpgsql
1058 1058
    AS $$
1059 1059
BEGIN
1060
	/* always generate standard exception if exists, even if table definition
1061
	would be invalid (which generates a variety of exceptions) */
1062
	IF util.relation_exists(relation) THEN RAISE duplicate_table; END IF;
1060 1063
	PERFORM util.eval(sql);
1061 1064
EXCEPTION
1062 1065
WHEN   duplicate_table
......
1073 1076

  
1074 1077

  
1075 1078
--
1076
-- Name: FUNCTION create_if_not_exists(sql text); Type: COMMENT; Schema: util; Owner: -
1079
-- Name: FUNCTION create_if_not_exists(sql text, relation text); Type: COMMENT; Schema: util; Owner: -
1077 1080
--
1078 1081

  
1079
COMMENT ON FUNCTION create_if_not_exists(sql text) IS '
1082
COMMENT ON FUNCTION create_if_not_exists(sql text, relation text) IS '
1080 1083
idempotent
1081 1084
';
1082 1085

  

Also available in: Unified diff