<commit_before>CREATE FUNCTION public.integer_to_array(value integer)
    RETURNS integer[]
AS $$
BEGIN
    RETURN ARRAY[value];
END;
$$ LANGUAGE plpgsql STABLE STRICT;


CREATE FUNCTION public.smallint_to_array(value smallint)
    RETURNS smallint[]
AS $$
BEGIN
    RETURN ARRAY[value];
END;
$$ LANGUAGE plpgsql STABLE STRICT;


-- Used to 'cast' from smallint to timestamp without timezone. This normally
-- isn't possible but we want to be able to switch. Implicitly, we just set all
-- values to NULL when converting a column from smallint to timestamp without
-- time zone.
CREATE FUNCTION public.smallint_to_timestamp_without_time_zone (smallint)
    RETURNS timestamp without time zone AS
$$
BEGIN
    RETURN NULL;
END;
$$ LANGUAGE plpgsql STABLE STRICT;


-- Same 'cast' support for timestamp with time zone
CREATE FUNCTION public.smallint_to_timestamp_with_time_zone (smallint)
    RETURNS timestamp with time zone
AS $$
BEGIN
    RETURN NULL;
END;
$$ LANGUAGE plpgsql STABLE STRICT;


CREATE FUNCTION public.column_names(namespace name, "table" name)
    RETURNS SETOF name
AS $$
    SELECT a.attname
    FROM pg_catalog.pg_class c
    JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
    JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
    WHERE
        n.nspname = $1 AND
        c.relname = $2 AND
        a.attisdropped = false AND
        a.attnum > 0;
$$ LANGUAGE SQL STABLE;


CREATE FUNCTION public.fst(anyelement, anyelement)
    RETURNS anyelement
AS $$
    SELECT $1;
$$ LANGUAGE SQL IMMUTABLE STRICT;


CREATE FUNCTION public.snd(anyelement, anyelement)
    RETURNS anyelement
AS $$
    SELECT $2;
$$ LANGUAGE SQL IMMUTABLE STRICT;


CREATE FUNCTION public.wal_location_to_int(text)
    RETURNS bigint
AS $$
    SELECT ('x' || lpad((regexp_split_to_array($1, '/'))[1] || lpad((regexp_split_to_array($1, '/'))[2], 8, '0'), 16, '0'))::bit(64)::bigint;
$$ LANGUAGE SQL IMMUTABLE STRICT;

COMMENT ON FUNCTION public.wal_location_to_int(text) IS
'Convert a textual WAL location in the form of ''1752F/CDC6E050'' into a bigint.
Use this function to monitor slave delay on the master:

SELECT
  client_addr,
  (public.wal_location_to_int(pg_current_xlog_location()) - public.wal_location_to_int(replay_location)) / 2^20 AS distance_mb
FROM pg_stat_replication;';


CREATE FUNCTION public.safe_division(numerator anyelement, denominator anyelement)
    RETURNS anyelement
AS $$
SELECT CASE
    WHEN $2 = 0 THEN
        NULL
    ELSE
        $1 / $2
    END;
$$ LANGUAGE SQL IMMUTABLE;

ALTER FUNCTION safe_division(anyelement, anyelement)
    OWNER TO postgres;


CREATE FUNCTION public.add_array(anyarray, anyarray) RETURNS anyarray
AS $$
SELECT array_agg((arr1 + arr2)) FROM<commit_msg>Remove wal location parsing function because PostgreSQL 9.4 has support for calculating with WAL locations<commit_after>CREATE FUNCTION public.integer_to_array(value integer)
    RETURNS integer[]
AS $$
BEGIN
    RETURN ARRAY[value];
END;
$$ LANGUAGE plpgsql STABLE STRICT;


CREATE FUNCTION public.smallint_to_array(value smallint)
    RETURNS smallint[]
AS $$
BEGIN
    RETURN ARRAY[value];
END;
$$ LANGUAGE plpgsql STABLE STRICT;


-- Used to 'cast' from smallint to timestamp without timezone. This normally
-- isn't possible but we want to be able to switch. Implicitly, we just set all
-- values to NULL when converting a column from smallint to timestamp without
-- time zone.
CREATE FUNCTION public.smallint_to_timestamp_without_time_zone (smallint)
    RETURNS timestamp without time zone AS
$$
BEGIN
    RETURN NULL;
END;
$$ LANGUAGE plpgsql STABLE STRICT;


-- Same 'cast' support for timestamp with time zone
CREATE FUNCTION public.smallint_to_timestamp_with_time_zone (smallint)
    RETURNS timestamp with time zone
AS $$
BEGIN
    RETURN NULL;
END;
$$ LANGUAGE plpgsql STABLE STRICT;


CREATE FUNCTION public.column_names(namespace name, "table" name)
    RETURNS SETOF name
AS $$
    SELECT a.attname
    FROM pg_catalog.pg_class c
    JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
    JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
    WHERE
        n.nspname = $1 AND
        c.relname = $2 AND
        a.attisdropped = false AND
        a.attnum > 0;
$$ LANGUAGE SQL STABLE;


CREATE FUNCTION public.fst(anyelement, anyelement)
    RETURNS anyelement
AS $$
    SELECT $1;
$$ LANGUAGE SQL IMMUTABLE STRICT;


CREATE FUNCTION public.snd(anyelement, anyelement)
    RETURNS anyelement
AS $$
    SELECT $2;
$$ LANGUAGE SQL IMMUTABLE STRICT;


CREATE FUNCTION public.safe_division(numerator anyelement, denominator anyelement)
    RETURNS anyelement
AS $$
SELECT CASE
    WHEN $2 = 0 THEN
        NULL
    ELSE
        $1 / $2
    END;
$$ LANGUAGE SQL IMMUTABLE;

ALTER FUNCTION safe_division(anyelement, anyelement)
    OWNER TO postgres;


CREATE FUNCTION public.add_array(anyarray, anyarray) RETURNS anyarray
AS $$
SELECT array_agg((arr1 + arr2)) FROM
{'fraction_non_alphanumeric': 0.08042457644417228, 'fraction_numerical': 0.009389671361502348, 'mean_word_length': 3.9246231155778895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2354406', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1594, 'n_words': 516}