For example, I have the strings oaaoaa
and aoaoao
.
I need the result: ooaoao
.
That is, it is necessary that the lines merge into one.
At the same time, the common part of the lines was preserved, and the mismatch was replaced by the symbol
How can this be done in Postgresql?
I try make this:
select 'text' | 'text'
but but of course got an operator error.
2
Answers
This iterates over each character position of the strings by generating a series of the length, so both strings must be the same length. If any character in a position is o then o else a.
fiddle
You chose the wrong data type. You should have taken
varbit
rather thantext
orvarchar
, then the|
would have done just what you want. You can still achieve your goal by translating the characters to 0 and 1 and casting the data to `varbit’: