verticapy.sql.functions.decode#
- verticapy.sql.functions.decode(expr: str | list[str] | StringSQL | list[StringSQL], *args) StringSQL #
Compares the expressions to each search value.
Parameters#
- expr: SQLExpression
Expression.
- args: SQLExpression
Infinite number of Expressions. The expression generated will look like:
- even:
CASE … WHEN expr = args[2 * i] THEN args[2 * i + 1] … END
- odd:
CASE … WHEN expr = args[2 * i] THEN args[2 * i + 1] … ELSE args[n] END
Returns#
- StringSQL
SQL string.
Examples#
First, let’s import the vDataFrame in order to create a dummy dataset.
from verticapy import vDataFrame
Now, let’s import the VerticaPy SQL functions.
import verticapy.sql.functions as vpf
We can now build a dummy dataset.
df = vDataFrame({"x": ['banana', 'apple', 'onion', 'potato']})
Now, let’s go ahead and apply the function.
df["type_x"] = vpf.decode( df["x"], 'banana', 'fruit', 'apple', 'fruit', 'vegetable', ) display(df)
AbcxVarchar(6)100%Abctype_xVarchar(9)100%1 banana fruit 2 apple fruit 3 onion vegetable 4 potato vegetable Note
It’s crucial to utilize VerticaPy SQL functions in coding, as they can be updated over time with new syntax. While SQL functions typically remain stable, they may vary across platforms or versions. VerticaPy effectively manages these changes, a task not achievable with pure SQL.
See also
vDataFrame.
eval()
: Evaluates the expression.