Classifies the sentiment of a text string as positive, negative, neutral, or mixed.
Syntax
AI_SENTIMENT([<resource_name>], <text>)Parameters
| Parameter | Description |
|---|---|
<resource_name> | Optional. The name of the AI resource to use. If omitted, the session default set by SET default_ai_resource is used. |
<text> | The text string to analyze. |
Return value
Returns one of the following strings:
| Value | Meaning |
|---|---|
positive | The text expresses a favorable or approving sentiment. |
negative | The text expresses an unfavorable or critical sentiment. |
neutral | The text expresses no strong positive or negative sentiment. |
mixed | The text contains both positive and negative sentiment. |
Returns NULL if any input value is NULL.
Results are generated by a Large Language Model (LLM) and may vary across runs.
Examples
Analyze a single string
Set a default resource and call the function without specifying one explicitly:
SET default_ai_resource = 'resource_name';
SELECT AI_SENTIMENT('SelectDB is a great DB system.') AS Result;+----------+
| Result |
+----------+
| positive |
+----------+Specify a resource explicitly
Pass the resource name as the first argument to override the session default:
SELECT AI_SENTIMENT('resrouce_name', 'I hate sunny days.') AS Result;+----------+
| Result |
+----------+
| negative |
+----------+Usage notes
If
<resource_name>is omitted, set a session default withSET default_ai_resource = '<resource_name>'before calling the function.Because the result is generated by an LLM, the same input may produce different outputs across runs. Do not rely on exact result reproducibility for production workflows that require deterministic output.