verticapy.sql.functions.extract#
- verticapy.sql.functions.extract(expr: str | list[str] | StringSQL | list[StringSQL], field: str) StringSQL #
Extracts a sub-field, such as year or hour, from a date/time expression.
Parameters#
- expr: SQLExpression
Expression.
- field: str
The field to extract. It must be one of the following: CENTURY, DAY, DECADE, DOQ, DOW, DOY, EPOCH, HOUR, ISODOW, ISOWEEK, ISOYEAR, MICROSECONDS, MILLENNIUM, MILLISECONDS, MINUTE, MONTH, QUARTER, SECOND, TIME ZONE, TIMEZONE_HOUR, TIMEZONE_MINUTE, WEEK, YEAR
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": ['11-03-1993', '12-03-1993']}) df["x"].astype("timestamp")
Now, let’s go ahead and apply the function.
df["months"] = vpf.extract(df["x"], "MONTH") display(df)
📅xTimestamp100%123monthsNumeric(20)100%1 1993-11-03 00:00:00 11.0 2 1993-12-03 00:00:00 12.0 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.