Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2447aab027
Fetching contributors…

Cannot retrieve contributors at this time

file 134 lines (112 sloc) 3.796 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
CREATE LANGUAGE plpgsql;
CREATE TYPE kc_row;

DROP FUNCTION kc_row_in(cstring) CASCADE;
CREATE FUNCTION kc_row_in(cstring)
    RETURNS kc_row
    AS 'libpg_kc', 'kc_row_in'
    LANGUAGE C IMMUTABLE STRICT;

DROP FUNCTION kc_row_out(kc_row) CASCADE;
CREATE FUNCTION kc_row_out(kc_row)
    RETURNS cstring
    AS 'libpg_kc' , 'kc_row_out'
    LANGUAGE C IMMUTABLE STRICT;

CREATE TYPE kc_row (
   INTERNALLENGTH = variable,
   INPUT = kc_row_in,
   OUTPUT = kc_row_out,
   ALIGNMENT = double,
   STORAGE = plain
);

DROP FUNCTION kc_key(kc_row);
CREATE FUNCTION kc_key(kc_row)
    RETURNS text
    AS 'libpg_kc', 'kc_key'
    LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION kc_val(kc_row)
    RETURNS bigint
    AS 'libpg_kc', 'kc_val'
    LANGUAGE C IMMUTABLE STRICT;

DROP FUNCTION kc_class(kc_row);
CREATE FUNCTION kc_class(kc_row)
    RETURNS text
    AS 'libpg_kc', 'kc_class'
    LANGUAGE C IMMUTABLE STRICT;

DROP FUNCTION kc_doctype(kc_row);
CREATE FUNCTION kc_doctype(kc_row)
    RETURNS text
    AS 'libpg_kc', 'kc_doctype'
    LANGUAGE C IMMUTABLE STRICT;

DROP FUNCTION kc_pop(kc_row);
CREATE FUNCTION kc_pop(kc_row)
    RETURNS text
    AS 'libpg_kc', 'kc_pop'
    LANGUAGE C IMMUTABLE STRICT;

DROP FUNCTION kc_psource(kc_row);
CREATE FUNCTION kc_psource(kc_row)
    RETURNS text
    AS 'libpg_kc', 'kc_psource'
    LANGUAGE C IMMUTABLE STRICT;

CREATE OR REPLACE FUNCTION kc_sum(bigint, kc_row)
    RETURNS bigint
    AS 'libpg_kc', 'kc_sum'
    LANGUAGE C IMMUTABLE;

CREATE AGGREGATE sum ( kc_row ) (
    SFUNC = kc_sum,
    INITCOND = 0,
    STYPE = bigint
);

CREATE OR REPLACE FUNCTION kcts(__start_time TIMESTAMPTZ, __oid BIGINT) RETURNS text AS $_$
    BEGIN
        RETURN to_char(__start_time, 'YYYY-MM-DD') || '/' || __oid;
    END;
$_$ Language 'plpgsql' IMMUTABLE STRICT;

/**
Returns multiple rows, being the expanded rows for every map found by the passed in inputs.
Indexed by: result_id:map_name:doctype:pop:psource

Call with -- result_id, map_name, doctype, pop, psource
Everything from map_name down can be null.

Return map_name doctype pop psource key value list
*/

DROP FUNCTION kcx(text, text, text);
CREATE OR REPLACE FUNCTION kcx(text, text, text)
    RETURNS SETOF kc_row
    AS 'libpg_kc', 'kc_expand'
    LANGUAGE C STABLE STRICT;

DROP FUNCTION kcx(text, text, text, text);
CREATE OR REPLACE FUNCTION kcx(IN text, IN text, IN text, IN text)
    RETURNS SETOF kc_row
    AS 'libpg_kc', 'kc_expand'
    LANGUAGE C STABLE STRICT;

DROP FUNCTION kcx(text, text, text, text, text);
CREATE OR REPLACE FUNCTION kcx(IN text, IN text, IN text, IN text, IN text)
    RETURNS SETOF kc_row
    AS 'libpg_kc', 'kc_expand'
    LANGUAGE C STABLE STRICT;

DROP FUNCTION kcx(text, text, text, text, text, text);
CREATE OR REPLACE FUNCTION kcx(IN text, IN text, IN text, IN text, IN text, IN text)
    RETURNS SETOF kc_row
    AS 'libpg_kc', 'kc_expand'
    LANGUAGE C STABLE STRICT;

DROP FUNCTION kcx(text, text, text, text, text, text, text);
CREATE OR REPLACE FUNCTION kcx(IN text, IN text, IN text, IN text, IN text, IN text, IN text)
    RETURNS SETOF kc_row
    AS 'libpg_kc', 'kc_expand'
    LANGUAGE C STABLE STRICT;

/**
Given the fixed values, writes (overrites) the kc entry.
map_name, start_time, new rid, array of rids, class, doctype, pop, psource
returns new kcid.
*/
DROP FUNCTION kcs (text, text, text, text array, text, text, text, text);
CREATE FUNCTION kcs (text, text, text, text array, text, text, text, text)
    RETURNS text
    AS 'libpg_kc', 'kc_shrink'
    LANGUAGE C STABLE STRICT;

/**
Also need a way to delete values in the kcdb
*/
DROP FUNCTION kcd (text, text, text array);
CREATE FUNCTION kcd (text, text, text array)
    RETURNS bigint
    AS 'libpg_kc', 'kc_delete'
    LANGUAGE C STABLE STRICT;
Something went wrong with that request. Please try again.