Do language PLPGSQL
$$
Declare var_s varchar='@ emp=1 and @ staff=2'.
The begin
With key_value as (
Select '@ emp as key_,' emp_1 as value_
The union
Select '@ staff', 'staff_2 as value_
)
Select the replace (var_s key_, value_) into var_s
The from key_value;
Raise notice '%', var_s; - get emp_1=1 and @ staff=2
End
$$
CodePudding user response:
Select the replace (var_s key_, value_) into var_s
The from key_value;
This statement per line var_s are original value, would not the first to record the results as the second initial.
Should use a for loop statement
Declare rec record;
.
For rec in the select * from key_value loop
Var_s:=replace (var_s, rec. Key_, rec. Value_);
end loop;