PostgreSQL unistr() Function

The PostgreSQL unistr() function converts escaped Unicode characters to normal strings.

unistr() Syntax

This is the syntax of the PostgreSQL unistr() function:

unistr(string)  text

Parameters

string

Required. It can be a regular string, or it can contain escaped Unicode characters.

Unicode characters can be specified in the following ways:

  • \XXXX(4 hexadecimal digits)
  • \+XXXXXX(6 hexadecimal digits)
  • \uXXXX(4 hexadecimal digits)
  • \UXXXXXXXX(8 hexadecimal digits)

Return value

The PostgreSQL unistr() function returns a string, which is the regular string corresponding to the escaped Unicode characters in the argument.

unistr() Examples

This example demonstrates the usage of the unistr() function:

SELECT unistr('\0441\043B\043E\043D');
 unistr
--------
 слон

Let’s look at another example:

SELECT
    unistr('d\0061t\+000061'),
    unistr('d\u0061t\U00000061');
 unistr | unistr
--------+--------
 data   | data