 CREATE FUNCTION trend.get_partition(trendstore trend.trendstore, index integer)
     RETURNS trend.partition
 AS $$
-    SELECT partition FROM trend.partition WHERE trendstore_id = $1.id AND table_name = trend.partition_name($1, $2);
+    SELECT partition
+    FROM trend.partition
+    WHERE trendstore_id = $1.id AND table_name = trend.partition_name($1, $2);
 $$ LANGUAGE SQL STABLE;
 
 
 CREATE FUNCTION trend.create_partition(trendstore trend.trendstore, index integer)
     RETURNS trend.partition
 AS $$
-    INSERT INTO trend.partition (table_name, trendstore_id, data_start, data_end, version)
-        VALUES (trend.partition_name($1, $2), $1.id, trend.index_to_timestamp($1.partition_size, $2), trend.index_to_timestamp($1.partition_size, $2 + 1), 4)
-        RETURNING partition;
+    INSERT INTO trend.partition(
+        table_name,
+        trendstore_id,
+        data_start,
+        data_end
+    )
+    VALUES (
+        trend.partition_name($1, $2),
+        $1.id,
+        trend.index_to_timestamp($1.partition_size, $2),
+        trend.index_to_timestamp($1.partition_size, $2 + 1)
+    )
+    RETURNING partition;
 $$ LANGUAGE SQL VOLATILE;
 
 

DECLARE
    max_modified timestamp with time zone;
BEGIN
    EXECUTE format('SELECT max(modified) FROM trend.%I WHERE timestamp = $1', trend.to_base_table_name($1)) INTO max_modified USING $2;

    RETURN max_modified;
END;

CREATE FUNCTION trend.populate_modified(trend.trendstore)
    RETURNS SETOF trend.modified
AS $$
    SELECT
        trend.populate_modified(partition)
    FROM trend.partition
    WHERE trendstore_id = $1.id;
$$ LANGUAGE SQL VOLATILE;


CREATE FUNCTION trend.populate_modified(character varying)
    RETURNS SETOF trend.modified
AS $$
    SELECT
        trend.populate_modified(partition)
    FROM trend.partition
    WHERE table_name = $1;
$$ LANGUAGE SQL VOLATILE;


