Function replace_latin1

The function has three implementations.

All implementations depend on the function is_latin1, the function is included in this repository.

replace_latin1(s text)

The function takes one parameter with characters to be checked and replaced with an empty string, if they are not part of latin1.

Example

SELECT replace_latin1('Some characters, ğ is Turkish and not latin1') AS res;

Result:

res
Some characters, is Turkish and not latin1

replace_latin1(s text, replacement text)

The function takes a second parameter which is used to replace all characters, which are not part of latin1.

Example

SELECT replace_latin1(
  'Some characters, ğ is Turkish and not latin1 and replaced with a g',
  'g'
) AS res;

Result:

res
Some characters, g is Turkish and not latin1 and replaced with a g

replace_latin1(s text, s_search text[], s_replace text[])

The function takes as first parameter a string which may or may not have none latin1 characters. The second parameter is an arrays containing all characters, that should be replaced. The third parameter is an array, too. The characters defined in s_search are replaced with the characters in s_replace, it takes the position in the array to identify which character should be replaced by which one.

Example

-- First identify the characters which should be replaced, which are {ğ,Ƶ}
SELECT return_not_part_of_latin1('ağbƵcğeƵ') AS res;

-- The ğ will be replaced whit a g and the Ƶ with a Z}
SELECT 'ağbƵcğeƵ' AS original
  , replace_latin1(
      'ağbƵcğeƵ',
      string_to_array('ğ,Ƶ', ','),
      string_to_array('g,Z', ',')
    ) AS res;

Result:

original res
ağbƵcğeƵ agbZcgeZ