Function is_encoding
The function checks if all characters are in included in a given encoding. That is especially useful, if you have to deal with exports into other encodings than the database encoding.
The function with two parameters uses UTF-8 as source encoding,
The one with three parameters uses the third parameter as source encoding.
Examples
SELECT is_encoding('Some characters', 'LATIN1') AS res;
Result:
| res |
|---|
| f |
SELECT is_encoding('Some characters, ğ is Turkish and not latin1', 'LATIN1') AS res;
-- Returns false: The Turkish character ğ is not part of latin1
Result:
| res |
|---|
| f |
SELECT is_encoding('Some characters', 'LATIN1', 'UTF8') AS res;
Result:
| res |
|---|
| t |
SELECT is_encoding('Some characters, ğ is Turkish and not latin1', 'UTF8', 'LATIN1') AS res;
-- Returns false: The Turkish character ğ is not part of latin1
Result:
| res |
|---|
| f |