Skip to content

Commit

Permalink
Edited as per the review comments from Nishant for NLS config file an…
Browse files Browse the repository at this point in the history
…d NLS_Upper function. Added NLS_LOWER and NLS_INITCAP.
  • Loading branch information
nidhibhammar committed Aug 5, 2024
1 parent a8e7e95 commit 4888018
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,111 +6,115 @@ navigation:
- nls_initcap
---

EDB Postgres Advanced Server version 17 and later provides the support for NLS functions. These functions uses the `edb_redwood_nls.config` file to map the NLS parameters with an equivalent ICU or libc's collate.
EDB Postgres Advanced Server version 17 and later provides the support for NLS functions. These functions uses the `edb_redwood_nls.config` file to map the NLS parameters with an equivalent PostgreSQL Collate.

## NLS config file

The `edb_redwood_nls.config` file maintains the list of NLS parameters mapping with an equivalent ICU or libc's collate. The NLS parameters and an equivalent collates 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 collate pairs.

<details><summary>The default list of NLS parameters mapping with an equivalent collates in the NLS config file:</summary>
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 `edb_redwood_nls.config` file maintains the list of NLS parameters mapping with an equivalent collate. The NLS parameters and an equivalent collates 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 collate pairs.

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

</details>

<br/>

You can add a new collation as `<schema_name>.<collation>` from `pg_collation` catalog mapped to a valid NLS parameter in the NLS config file. Add this mapping before using the NLS parameter in the NLS functions. Add a new entry to the config file using the `edb_nls_cf_insert` function. Reload the config file after adding a new entry using `edb_nls_cf_reload` function.
You can add a new entry in the NLS config file,
- manually editing the config file in the format `NLS_parameter,<schema_name>.<collation>`.
- or using the `edb_nls_cf_insert` function.

**Usage of NLS config file**
where `<schema_name>.<collation>` is to be obtained from `pg_collation` catalog and mapped to a valid NLS parameter.

- Each client session reads the config file and stores the NLS parameters and collation values in in-mem HASH data structure when any of the NLS function is called for the first time.
Add this mapping before using the NLS parameter in the NLS functions. Reload the config file for other sessions after adding a new entry using `edb_nls_cf_reload` function.

- The config file is read row by row while parsing the SQL statement including the NLS functions.
**Usage of NLS config file**

- The changes done to the config file in a session updates the in-mem HASH data structure with new mappings. The changes done in a session gets updated in other sessions only after reloading the config file or after the other sessions are re-started.
- Each client session reads the config file and stores the NLS parameters and collate values in in-mem HASH data structure when any of the NLS function is called for the first time.

- It is recommended to clean up the in-mem HASH during shutdown of the databases.
- The parsing logic will read each row sequentially, segregate NLS parameters and collate values, and then store them in the right data structure.

- The changes done to the config file in a session updates the in-mem HASH data structure with new mappings. The changes done in a session gets updated in other sessions only after reloading the config file or after the other sessions are re-started.


The available functions for managing the NLS config file are listed in the following table:
Expand All @@ -137,16 +141,21 @@ The available functions for managing the NLS config file are listed in the follo
This example shows how to add a new entry in the NLS config file:

```
SELECT edb_nls_cf_insert('xgerman', 'de-x-icu');
SELECT edb_nls_cf_insert('xgerman', '"pg_catalog"."de-x-icu"');
__OUTPUT__
edb_nls_config_file_insert
----------------------------
SUCCESS: Entry Inserted
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)
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
---
title: "NLS_INITCAP function"
---
---

`NLS_INITCAP` returns `<outputstring> TEXT`, with all letters in uppercase.


```sql
NLS_INITCAP(<inputstring> TEXT [, <'nlsparam'> TEXT])
```

Where,

`inputstring` is of the TEXT data type.

`nlsparam` is of the TEXT data type.

The `<outputstring>` is of the TEXT data type. The return string is in the same character set as `inputstring`.

## Examples

This example shows NLS_INITCAP function with default mapping of NLS parameter and a collation value.

```sql
SELECT NLS_INITCAP('Gloße', 'NLS_SORT = xdanish');
__OUTPUT__
NLS_INITCAP
-----------
GLOßE
(1 row)
```


This example shows how to add a new entry of NLS parameter and a collation value in the NLS config file using `edb_nls_cf_insert` function.

```sql
SELECT edb_nls_cf_insert('xdanish', '"pg_catalog"."da-x-icu"');
__OUTPUT__
edb_nls_cf_insert
-------------------

(1 row)
```


This example shows NLS_INITCAP function after adding a new entry to the NLS config file.

```sql
SELECT NLS_INITCAP('Gloße', 'NLS_SORT = xdanish');
__OUTPUT__
NLS_INITCAP
-----------
GLOSSE
(1 row)
```


This example shows NLS_INITCAP function for simple input string.

```sql
SELECT NLS_INITCAP('abcDef', 'NLS_SORT = XGERMAN');
NLS_INITCAP
-----------
Abacdef
(1 row)
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,64 @@
title: "NLS_LOWER function"
---

`NLS_LOWER` returns char, with all letters in lowercase.
`NLS_LOWER` returns `<outputstring> TEXT`, with all letters in uppercase.


```sql
NLS_LOWER(char [,'nlsparam'])
NLS_LOWER(<inputstring> TEXT [, <'nlsparam'> TEXT])
```

Where char and 'nlsparam' can be any of the data types like CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The returned string is of VARCHAR2 data type if char is a character datatype and a LOB if char is a LOB data type. The return string is in the same character set as char.
Where,

`inputstring` is of the TEXT data type.

`nlsparam` is of the TEXT data type.

The `<outputstring>` is of the TEXT data type. The return string is in the same character set as `inputstring`.

## Examples

This example shows NLS_LOWER function with default mapping of NLS parameter and a collation value.

```sql
SELECT nls_lower('ABCdEF', 'NLS_SORT = XDANISH');
SELECT NLS_LOWER('Gloße', 'NLS_SORT = xdanish');
__OUTPUT__
nls_lower
NLS_LOWER
-----------
abcdef
GLOßE
(1 row)
```


This example shows how to add a new entry of NLS parameter and a collation value in the NLS config file using `edb_nls_cf_insert` function.

```sql
SELECT edb_nls_cf_insert('xdanish', '"pg_catalog"."da-x-icu"');
__OUTPUT__
edb_nls_cf_insert
-------------------

(1 row)
```


This example shows NLS_LOWER function after adding a new entry to the NLS config file.

```sql
SELECT nls_lower('ABCdEF');
SELECT NLS_LOWER('Gloße', 'NLS_SORT = xdanish');
__OUTPUT__
nls_lower
NLS_LOWER
-----------
GLOSSE
(1 row)
```


This example shows NLS_LOWER function for simple input string.

```sql
SELECT NLS_LOWER('abcDef', 'NLS_SORT = XGERMAN');
NLS_LOWER
-----------
abcdef
(1 row)
Expand Down
Loading

0 comments on commit 4888018

Please sign in to comment.