Skip to content

Commit 7e9089f

Browse files
author
raghav
committed
Add support for bulk update in ll_bitemporal_update_select functions.
Use the FROM clause in the UPDATE statement to support bulk data update.
1 parent 5e5c0cb commit 7e9089f

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

sql/ll_bitemporal_update_select.sql

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ v_list_of_fields_to_insert text:=' ';
1515
v_list_of_fields_to_insert_excl_effective text;
1616
v_table_attr text[];
1717
v_now timestamptz:=now();-- so that we can reference this time
18+
x_alias_list_of_fields text:= 'x.' || REPLACE(p_list_of_fields, ',', ',x.');
19+
x_alias_p_search_fields text:= 'x.' || REPLACE(p_search_fields, ',', ',x.');
20+
t_alias_p_search_fields text:= 't.' || REPLACE(p_search_fields, ',', ',t.');
1821
BEGIN
1922
IF lower(p_asserted)<v_now::date --should we allow this precision?...
2023
OR upper(p_asserted)< 'infinity'
@@ -97,15 +100,15 @@ EXECUTE format($i$INSERT INTO %s ( %s, effective, asserted )
97100
);
98101

99102
--update new record(s) in new assertion rage with new values
100-
101-
EXECUTE format($u$ UPDATE %s t SET (%s) = (%s)
102-
WHERE ( %s ) in ( %s ) AND effective=%L
103-
AND asserted=%L $u$
103+
104+
EXECUTE format($u$ UPDATE %s t SET (%s) = (%s)
105+
FROM (%s) as x WHERE (%s) = (%s) AND effective=%L AND asserted=%L $u$
104106
, p_table
105107
, p_list_of_fields
108+
, x_alias_list_of_fields
106109
, p_values_selected_update
107-
, p_search_fields
108-
, p_values_selected_search
110+
, x_alias_p_search_fields
111+
, t_alias_p_search_fields
109112
, p_effective
110113
, p_asserted);
111114

@@ -136,6 +139,9 @@ v_table text:=p_schema_name||'.'||p_table_name;
136139
v_keys_old int[];
137140
v_keys int[];
138141
v_now timestamptz:=now();-- so that we can reference this time
142+
x_alias_list_of_fields text:= 'x.' || REPLACE(p_list_of_fields, ',', ',x.');
143+
x_alias_p_search_fields text:= 'x.' || REPLACE(p_search_fields, ',', ',x.');
144+
t_alias_p_search_fields text:= 't.' || REPLACE(p_search_fields, ',', ',t.');
139145
BEGIN
140146
IF lower(p_asserted)<v_now::date --should we allow this precision?...
141147
OR upper(p_asserted)< 'infinity'
@@ -215,12 +221,15 @@ into v_keys;
215221

216222

217223
EXECUTE format($u$ UPDATE %s t SET (%s) = (%s)
218-
WHERE ( %s ) in ( %s ) $u$
224+
FROM (%s) as x WHERE ( %s ) IN ( %s ) AND (%s) = (%s) $u$
219225
, v_table
220226
, p_list_of_fields
227+
, x_alias_list_of_fields
221228
, p_values_selected_update
222229
, v_serial_key
223-
, array_to_string(v_keys,','));
230+
, array_to_string(v_keys,',')
231+
, x_alias_p_search_fields
232+
, t_alias_p_search_fields);
224233

225234

226235

0 commit comments

Comments
 (0)