@@ -18,23 +18,35 @@ CREATE OR REPLACE FUNCTION @extschema@.create_hash_partitions(
1818) RETURNSINTEGER AS
1919$$
2020DECLARE
21- v_relnameTEXT ;
21+ v_relnameTEXT ;
2222v_child_relnameTEXT ;
23- v_typeTEXT ;
23+ v_typeTEXT ;
24+ v_plain_schemaTEXT ;
25+ v_plain_relnameTEXT ;
26+ v_hashfuncTEXT ;
2427BEGIN
2528v_relname := @extschema@.validate_relname(relation);
2629attribute := lower (attribute);
2730PERFORM @extschema@.common_relation_checks(relation, attribute);
2831
2932v_type := @extschema@.get_attribute_type_name(v_relname, attribute);
30- IF v_type::regtype!= ' integer' ::regtype THEN
31- RAISE EXCEPTION' Attribute type must be INTEGER' ;
32- END IF;
33+ -- IF v_type::regtype != 'integer'::regtype THEN
34+ -- RAISE EXCEPTION 'Attribute type must be INTEGER';
35+ -- END IF;
36+
37+ SELECT * INTO v_plain_schema, v_plain_relname
38+ FROM @extschema@.get_plain_schema_and_relname(relation);
39+
40+ v_hashfunc := @extschema@.get_type_hash_func(v_type::regtype::oid )::regproc;
3341
3442/* Create partitions and update pg_pathman configuration*/
3543FOR partnumIN 0 ..partitions_count- 1
3644LOOP
37- v_child_relname := @extschema@.get_schema_qualified_name(relation,' .' , suffix := ' _' || partnum);
45+ -- v_child_relname := @extschema@.get_schema_qualified_name(relation, '.', suffix := '_' || partnum);
46+ v_child_relname := format(' %s.%s' ,
47+ v_plain_schema,
48+ quote_ident(v_plain_relname|| ' _' || partnum));
49+
3850EXECUTE format(' CREATE TABLE %s (LIKE %s INCLUDING ALL)'
3951, v_child_relname
4052, v_relname);
4355, v_child_relname
4456, v_relname);
4557
46- EXECUTE format(' ALTER TABLE %s ADD CHECK (%s %% %s = %s)'
58+ EXECUTE format(' ALTER TABLE %s ADD CHECK (@extschema@.get_hash(%s(%s), %s) = %s)'
4759 , v_child_relname
60+ , v_hashfunc
4861 , attribute
4962 , partitions_count
5063 , partnum);
@@ -83,7 +96,7 @@ DECLARE
8396DECLARE
8497hash INTEGER;
8598BEGIN
86- hash := NEW.%s %% %s ;
99+ hash :=@extschema@.get_hash(%s( NEW.%s), %s) ;
87100%s
88101RETURN NULL;
89102END $body$ LANGUAGE plpgsql;' ;
@@ -93,11 +106,11 @@ DECLARE
93106BEFORE INSERT ON %s
94107FOR EACH ROW EXECUTE PROCEDURE %s();' ;
95108triggernameTEXT ;
96- -- fields TEXT;
97- -- fields_format TEXT;
98109insert_stmtTEXT ;
99- relnameTEXT ;
100- schemaTEXT ;
110+ relnameTEXT ;
111+ schemaTEXT ;
112+ atttypeTEXT ;
113+ hashfuncTEXT ;
101114BEGIN
102115/* drop trigger and corresponding function*/
103116PERFORM @extschema@.drop_hash_triggers(relation);
@@ -113,7 +126,11 @@ BEGIN
113126funcname := schema|| ' .' || quote_ident(format(' %s_insert_trigger_func' , relname));
114127triggername := quote_ident(format(' %s_%s_insert_trigger' , schema, relname));
115128
116- func := format(func, funcname, attr, partitions_count, insert_stmt);
129+ /* base hash function for type*/
130+ atttype := @extschema@.get_attribute_type_name(relation, attr);
131+ hashfunc := @extschema@.get_type_hash_func(atttype::regtype::oid )::regproc;
132+
133+ func := format(func, funcname, hashfunc, attr, partitions_count, insert_stmt);
117134trigger := format(trigger, triggername, relation, funcname);
118135EXECUTE func;
119136EXECUTE trigger;
@@ -197,8 +214,8 @@ DECLARE
197214$body$
198215DECLARE old_hash INTEGER; new_hash INTEGER; q TEXT;
199216BEGIN
200- old_hash := OLD.%2$s %% % 3$s;
201- new_hash := NEW.%2$s %% % 3$s;
217+ old_hash :=@extschema@.get_hash(%9$s( OLD.%2$s), % 3$s) ;
218+ new_hash :=@extschema@.get_hash(%9$s( NEW.%2$s), % 3$s) ;
202219IF old_hash = new_hash THEN RETURN NEW; END IF;
203220q := format(' ' DELETE FROM %8$s WHERE %4$s' ' , old_hash);
204221EXECUTE q USING %5$s;
@@ -223,6 +240,8 @@ DECLARE
223240funcnameTEXT ;
224241triggernameTEXT ;
225242child_relname_formatTEXT ;
243+ atttypeTEXT ;
244+ hashfuncTEXT ;
226245BEGIN
227246relation := @extschema@.validate_relname(relation);
228247
@@ -252,9 +271,13 @@ BEGIN
252271child_relname_format := plain_schema|| ' .' || quote_ident(plain_relname|| ' _%s' );
253272triggername := quote_ident(format(' %s_%s_update_trigger' , plain_schema, plain_relname));
254273
274+ /* base hash function for type*/
275+ atttype := @extschema@.get_attribute_type_name(relation, attr);
276+ hashfunc := @extschema@.get_type_hash_func(atttype::regtype::oid )::regproc;
277+
255278/* Format function definition and execute it*/
256279func := format(func, funcname, attr, partitions_count, att_val_fmt,
257- old_fields, att_fmt, new_fields, child_relname_format);
280+ old_fields, att_fmt, new_fields, child_relname_format, hashfunc );
258281EXECUTE func;
259282
260283/* Create triggers on child relations*/