Name
diff, diff_apply, diff_reverse — compute, apply and invert line-based textual diffs
Synopsis
any diff(
|
in old_text varchar, |
in new_text varchar); |
varchar diff_apply(
|
in old_text varchar, |
in patch any); |
any diff_reverse(
|
in patch any); |
Description
diff computes the line-based difference between
old_text and new_text and
returns a patch as a vector of edit operations (insertions and deletions
with line offsets and text). The patch can be stored, transmitted, or
applied to reconstruct one version of the text from the other.
diff_apply applies patch to
old_text and returns the resulting new text. The
patch must be in the form produced by diff.
diff_reverse returns the inverse patch: applying it
to the new text yields the old text. Useful for storing reversible
revision histories.
Examples
Example 24.243. Round-trip a text
SQL> declare p any;
p := diff ('one\ntwo\n', 'one\nTWO\nthree\n');
select diff_apply ('one\ntwo\n', p);