NLS functions v17

EDB Postgres Advanced Server version 17 and later provides the support for NLS functions. These functions uses the NLS config file to map the NLS parameters with an equivalent PostgreSQL Collation.

NLS config file

The edb_redwood_nls.config file maintains the list of NLS parameters mapping with an equivalent collation. The NLS parameters and an equivalent collation are listed in each row in the config file separated by commas respectively. The config file contains a default list of NLS parameters and an equivalent collation pairs. The NLS config file is located at EPAS_INSTALLATION_DIRECTORY/share/postgresql/contrib/.

The default NLS config file contents:ARABIC,"pg_catalog"."default"
ARABIC_MATCH,"pg_catalog"."default"
ARABIC_ABJ_SORT,"pg_catalog"."default"
ARABIC_ABJ_MATCH,"pg_catalog"."default"
ASCII7,"pg_catalog"."default"
AZERBAIJANI,"pg_catalog"."default"
XAZERBAIJANI,"pg_catalog"."default"
BENGALI,"pg_catalog"."default"
BIG5,"pg_catalog"."default"
BINARY,"pg_catalog"."default"
BULGARIAN,"pg_catalog"."default"
CATALAN,"pg_catalog"."default"
XCATALAN,"pg_catalog"."default"
CROATIAN,"pg_catalog"."default"
XCROATIAN,"pg_catalog"."default"
CZECH,"pg_catalog"."default"
XCZECH,"pg_catalog"."default"
CZECH_PUNCTUATION,"pg_catalog"."default"
XCZECH_PUNCTUATION,"pg_catalog"."default"
DANISH,"pg_catalog"."default"
XDANISH,"pg_catalog"."default"
DUTCH,"pg_catalog"."default"
XDUTCH,"pg_catalog"."default"
EBCDIC,"pg_catalog"."default"
EEC_EURO,"pg_catalog"."default"
EEC_EUROPA3,"pg_catalog"."default"
ESTONIAN,"pg_catalog"."default"
FINNISH,"pg_catalog"."default"
FRENCH,"pg_catalog"."default"
XFRENCH,"pg_catalog"."default"
GERMAN,"pg_catalog"."default"
XGERMAN,"pg_catalog"."default"
GERMAN_DIN,"pg_catalog"."default"
XGERMAN_DIN,"pg_catalog"."default"
GBK,"pg_catalog"."default"
GREEK,"pg_catalog"."default"
HEBREW,"pg_catalog"."default"
HKSCS,"pg_catalog"."default"
HUNGARIAN,"pg_catalog"."default"
XHUNGARIAN,"pg_catalog"."default"
ICELANDIC,"pg_catalog"."default"
INDONESIAN,"pg_catalog"."default"
ITALIAN,"pg_catalog"."default"
LATIN,"pg_catalog"."default"
LATVIAN,"pg_catalog"."default"
LITHUANIAN,"pg_catalog"."default"
MALAY,"pg_catalog"."default"
NORWEGIAN,"pg_catalog"."default"
POLISH,"pg_catalog"."default"
PUNCTUATION,"pg_catalog"."default"
XPUNCTUATION,"pg_catalog"."default"
ROMANIAN,"pg_catalog"."default"
RUSSIAN,"pg_catalog"."default"
SLOVAK,"pg_catalog"."default"
XSLOVAK,"pg_catalog"."default"
SLOVENIAN,"pg_catalog"."default"
XSLOVENIAN,"pg_catalog"."default"
SPANISH,"pg_catalog"."default"
XSPANISH,"pg_catalog"."default"
SWEDISH,"pg_catalog"."default"
SWISS,"pg_catalog"."default"
XSWISS,"pg_catalog"."default"
TURKISH,"pg_catalog"."default"
XTURKISH,"pg_catalog"."default"
UKRAINIAN,"pg_catalog"."default"
UNICODE_BINARY,"pg_catalog"."default"
VIETNAMESE,"pg_catalog"."default"
WEST_EUROPEAN,"pg_catalog"."default"
XWEST_EUROPEAN,"pg_catalog"."default"
CANADIAN_M,"pg_catalog"."default"
DANISH_M,"pg_catalog"."default"
FRENCH_M,"pg_catalog"."default"
GENERIC_M,"pg_catalog"."default"
JAPANESE_M,"pg_catalog"."default"
KOREAN_M,"pg_catalog"."default"
SPANISH_M,"pg_catalog"."default"
THAI_M,"pg_catalog"."default"
SCHINESE_RADICAL_M,"pg_catalog"."default"
SCHINESE_STROKE_M,"pg_catalog"."default"
SCHINESE_PINYIN_M,"pg_catalog"."default"
TCHINESE_RADICAL_M,"pg_catalog"."default"
TCHINESE_STROKE_M,"pg_catalog"."default"

The config file can contain multiple mappings for a single NLS parameter. You can add a new mapping for an existing NLS parameter. The latest added mapping will be used for the NLS function operations.

Before using NLS functions for a NLS parameter, add a new mapping in the NLS config file,

  • manually by editing the config file in the format NLS_parameter,<schema_name>.<collation>.
  • or by using the edb_nls_cf_insert function. When using edb_nls_cf_insert function it's crucial to ensure that the file has the correct write permissions. Without the appropriate permissions, attempts to modify the file will fail, potentially leading to errors or incomplete configurations.

where <schema_name>.<collation> is to be obtained from pg_collation catalog and mapped to a valid NLS parameter. Only the collations with an encoding of -1 (which represents "any encoding") or the database encoding are allowed.

If you're encountering NOTICE messages due to invalid entries in the NLS config file, the best approach is to manually remove those invalid entries. These messages typically occur when the database is trying to reference collations that doesn't exist or are incorrectly specified in the configuration file.

NOTICE messages examples

Example 1 - NOTICE: invalid nls entry (XGERMAN.xyz-pqr) in nls config file at line number 83, skipping

Example 2 - NOTICE: pg collation not found for entry (XGERMAN,abc) in nls config file at line number 84, skipping


It's important to recognize that collation values are platform-dependent, meaning a collation available on one platform might not be present on another. To avoid compatibility issues, always use collations that are available in the pg_collation table within your environment.

Each client session reads the config file and stores the NLS parameters and collation values in in-memory HASH data structure when any of the NLS function is called for the first time. The parsing logic will read each row sequentially, segregate NLS parameters and collation values, and then store them in the right data structure.

Making changes to the config file manually requires you to reload the NLS config files in all sessions or restart the session to work with the updated mappings. Using the edb_nls_cf_insert function to modify the config file in a session will update the in-memory HASH data structure with new mappings. Changes made in a session will only affect other sessions after the config file is reloaded or after the other sessions are restarted.

The available functions for managing the NLS config file are listed in the following table:

FunctionReturn typeDescription
edb_nls_cf_insert(nls TEXT, collation TEXT)VOIDAdds a new mapping in the NLS config file with the given NLS parameter and a mapping collation.
edb_nls_cf_reload()VOIDReloads the NLS config file and updates the NLS parameter and a mapping collation in in-memory HASH data structure.
edb_nls_cf_hash_dump(OUT nls TEXT, OUT collationid INT)RECORDDumps the NLS parameter and a mapping collation HASH contents on the client session.
edb_nls_cf_dump(OUT nls TEXT, OUT collation TEXT)RECORDDumps the existing NLS config file contents on the client session.

Supported NLS functions

Examples

This example shows how to add a new mapping in the NLS config file:

SELECT edb_nls_cf_insert('xgerman', '"pg_catalog"."de-x-icu"');
Output
 edb_nls_cf_insert 
-------------------
 
(1 row)

This example shows how to reload the NLS config file:

SELECT edb_nls_cf_reload();
Output
 edb_nls_cf_reload 
-------------------
 
(1 row)