SQL92 définit les fonctions chaîne avec une syntaxe spécifique. Certaines sont implémentées en utilisant d'autres fonctions Postgres. Les types chaîne supportés par SQL92 sont char, varchar, et text.
Tableau 5-3. Fonctions chaîne Postgres
| Fonction | Returns | Description | Exemple |
|---|---|---|---|
| char_length(string) | int4 | longueur de chaîne | char_length('jose') |
| character_length(string) | int4 | longueur de chaîne | char_length('jose') |
| lower(string) | string | convert string to lower case | lower('TOM') |
| octet_length(string) | int4 | stockage de la longueur de chaîne | octet_length('jose') |
| position(string in string) | int4 | lieu de la sous-chaîne spécifiée | position('o' in 'Tom') |
| substring(string [from int] [for int]) | string | extrait la sous-chaîne spécifiée | substring('Tom' from 2 for 2) |
| trim([leading|trailing|both] [string] from string) | string | met en odre les caractères de la chaîne | trim(both 'x' from 'xTomx') |
| upper(text) | text | convert text to upper case | upper('tom') |
Certaines fonctions chaîne sont disponibles comme les types text, varchar(), et char(). Certaines sont utilisées en interne pour implémenter les fonctions chaîne SQL92 ci-dessous.
Tableau 5-4. Fonctions chaîne SQL92
| Fonction | Returns | Description | Exemple |
|---|---|---|---|
| char(text) | char | convertit du texte en type char | char('text string') |
| char(varchar) | char | convertit varchar en type char | char(varchar 'varchar string') |
| initcap(text) | text | first letter of each word to upper case | initcap('thomas') |
| lpad(text,int,text) | text | left pad string to specified length | lpad('hi',4,'??') |
| ltrim(text,text) | text | left trim characters from text | ltrim('xxxxtrim','x') |
| textpos(text,text) | text | localise la sous-chaîne spécifiée | position('high','ig') |
| rpad(text,int,text) | text | right pad string to specified length | rpad('hi',4,'x') |
| rtrim(text,text) | text | right trim characters from text | rtrim('trimxxxx','x') |
| substr(text,int[,int]) | text | extrait la sous-chaîne spécifiée | substr('hi there',3,5) |
| text(char) | text | convertit char en type text | text('char string') |
| text(varchar) | text | convertit varchar en type text | text(varchar 'varchar string') |
| translate(text,from,to) | text | convertit character en chaîne | translate('12345', '1', 'a') |
| varchar(char) | varchar | convertit char en type varchar | varchar('char string') |
| varchar(text) | varchar | convertit text en type varchar | varchar('text string') |
La plupart des fonctions explicitement définies pour text fonctionneront pour les arguments char() et varchar().