Translates text into a specified language using a large language model (LLM).
Syntax
AI_TRANSLATE([<resource_name>], <text>, <target_language>)Parameters
| Parameter | Description |
|---|---|
<resource_name> | Optional. The name of the AI resource to use. If omitted, the resource set by SET default_ai_resource is used. |
<text> | The text to translate. |
<target_language> | The target language code, such as zh-CN or fr. |
Return value
Returns the translated text as a string.
Returns
NULLif any input value isNULL.The output may vary between calls because it is generated by an LLM.
Examples
Example 1: Use the default AI resource
Set a default resource, then call AI_TRANSLATE with two arguments:
SET default_ai_resource = 'resource_name';
SELECT AI_TRANSLATE('In my mind, SelectDB is the best database management system.', 'zh-CN') AS Result;Output:
+-----------------------------------------------------------------+
| Result |
+-----------------------------------------------------------------+
| In my opinion, SelectDB is the best database management system. |
+-----------------------------------------------------------------+Example 2: Specify a resource explicitly
Pass the resource name as the first argument to override the default:
SELECT AI_TRANSLATE('resource_name', 'This is an example', 'fr') AS Result;Output:
+------------------+
| Result |
+------------------+
| Voici un exemple |
+------------------+