Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e2d48c

Browse files
committed
alter functions with renamed args (1.3)
1 parent11faec2 commit4e2d48c

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

‎pg_pathman--1.2--1.3.sql‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,71 @@ DROP FUNCTION @extschema@.drop_range_partition(REGCLASS, BOOLEAN);
6868
DROPFUNCTION @extschema@.attach_range_partition(REGCLASS, REGCLASS, ANYELEMENT, ANYELEMENT);
6969
DROPFUNCTION @extschema@.detach_range_partition(REGCLASS);
7070
DROPFUNCTION @extschema@.merge_range_partitions_internal(REGCLASS, REGCLASS, REGCLASS, ANYELEMENT);
71+
DROPFUNCTION @extschema@.copy_foreign_keys(REGCLASS, REGCLASS);
72+
DROPFUNCTION @extschema@.invoke_on_partition_created_callback(REGCLASS, REGCLASS, REGPROCEDURE, ANYELEMENT, ANYELEMENT);
73+
DROPFUNCTION @extschema@.invoke_on_partition_created_callback(REGCLASS, REGCLASS, REGPROCEDURE);
74+
7175

7276
/* ------------------------------------------------------------------------
7377
* Alter functions' modifiers
7478
* ----------------------------------------------------------------------*/
7579
ALTERFUNCTION @extschema@.pathman_set_param(REGCLASS,TEXT, ANYELEMENT) STRICT;
7680

81+
7782
/* ------------------------------------------------------------------------
7883
* (Re)create functions
7984
* ----------------------------------------------------------------------*/
85+
86+
/*
87+
* Invoke init_callback on RANGE partition.
88+
*/
89+
CREATEOR REPLACE FUNCTION @extschema@.invoke_on_partition_created_callback(
90+
parent_relidREGCLASS,
91+
partition_relidREGCLASS,
92+
init_callbackREGPROCEDURE,
93+
start_valueANYELEMENT,
94+
end_valueANYELEMENT)
95+
RETURNS VOIDAS'pg_pathman','invoke_on_partition_created_callback'
96+
LANGUAGE C;
97+
98+
99+
/*
100+
* Invoke init_callback on HASH partition.
101+
*/
102+
CREATEOR REPLACE FUNCTION @extschema@.invoke_on_partition_created_callback(
103+
parent_relidREGCLASS,
104+
partition_relidREGCLASS,
105+
init_callbackREGPROCEDURE)
106+
RETURNS VOIDAS'pg_pathman','invoke_on_partition_created_callback'
107+
LANGUAGE C;
108+
109+
110+
/*
111+
* Copy all of parent's foreign keys.
112+
*/
113+
CREATEOR REPLACE FUNCTION @extschema@.copy_foreign_keys(
114+
parent_relidREGCLASS,
115+
partition_relidREGCLASS)
116+
RETURNS VOIDAS
117+
$$
118+
DECLARE
119+
recRECORD;
120+
121+
BEGIN
122+
PERFORM @extschema@.validate_relname(parent_relid);
123+
PERFORM @extschema@.validate_relname(partition_relid);
124+
125+
FOR recIN (SELECToidas conidFROMpg_catalog.pg_constraint
126+
WHERE conrelid= parent_relidAND contype='f')
127+
LOOP
128+
EXECUTE format('ALTER TABLE %s ADD %s',
129+
partition_relid::TEXT,
130+
pg_catalog.pg_get_constraintdef(rec.conid));
131+
END LOOP;
132+
END
133+
$$ LANGUAGE plpgsql STRICT;
134+
135+
80136
CREATEOR REPLACE FUNCTION @extschema@.set_init_callback(
81137
relationREGCLASS,
82138
callbackREGPROCEDURE DEFAULT0)
@@ -945,6 +1001,50 @@ RETURNS TEXT AS 'pg_pathman', 'build_range_condition'
9451001
LANGUAGE C;
9461002

9471003

1004+
/*
1005+
* Old school way to distribute rows to partitions.
1006+
*/
1007+
CREATEOR REPLACE FUNCTION @extschema@.partition_data(
1008+
parent_relidREGCLASS,
1009+
OUT p_totalBIGINT)
1010+
AS
1011+
$$
1012+
BEGIN
1013+
p_total :=0;
1014+
1015+
/* Create partitions and copy rest of the data*/
1016+
EXECUTE format('WITH part_data AS (DELETE FROM ONLY %1$s RETURNING *)
1017+
INSERT INTO %1$s SELECT * FROM part_data',
1018+
parent_relid::TEXT);
1019+
1020+
/* Get number of inserted rows*/
1021+
GET DIAGNOSTICS p_total= ROW_COUNT;
1022+
RETURN;
1023+
END
1024+
$$
1025+
LANGUAGE plpgsql STRICT
1026+
SETpg_pathman.enable_partitionfilter=on;
1027+
1028+
/*
1029+
* Add a row describing the optional parameter to pathman_config_params.
1030+
*/
1031+
CREATEOR REPLACE FUNCTION @extschema@.pathman_set_param(
1032+
relationREGCLASS,
1033+
paramTEXT,
1034+
valueANYELEMENT)
1035+
RETURNS VOIDAS
1036+
$$
1037+
BEGIN
1038+
EXECUTE format('INSERT INTO @extschema@.pathman_config_params
1039+
(partrel, %1$s) VALUES ($1, $2)
1040+
ON CONFLICT (partrel) DO UPDATE SET %1$s = $2', param)
1041+
USING relation, value;
1042+
END
1043+
$$
1044+
LANGUAGE plpgsql;
1045+
1046+
1047+
9481048
/* ------------------------------------------------------------------------
9491049
* Final words of wisdom
9501050
* ----------------------------------------------------------------------*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp