Using the Translate Function in YSQL

The translate() function in both PostgreSQL and YugabyteDB’s Postgres compatible YSQL API, does one-to-one translation of characters in a single operation.

The basic syntax of the function is:

				
					TRANSLATE(Main_String, String_from_set_to_replace, Replacement_String)
				
			

Example:

HAL 9000 is a fictional artificial intelligence character and the main antagonist in Arthur C. Clarke’s Space Odyssey series.

The name HAL comes from translating the letters from IBM, left shifting the characters!

				
					yugabyte=# SELECT translate('IBM', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'ZABCDEFGHIJKLMNOPQRSTUVWXY') "AI Gone Awry";
 AI Gone Awry
--------------
 HAL
(1 row)
				
			

Have Fun!

The birds have finally found the bath!