Skip to main content

Functions

Updated Jan 15, 2022 ·

String Functions

Snowflake provides useful functions for working with text data.

  • INITCAP – Capitalizes each word in a string.

    Example:

    SELECT INITCAP(name) AS capitalized_name FROM pizza_type;

    Result:

    namecapitalized_name
    pepperoniPepperoni
    bbq_chickenBbq Chicken
  • CONCAT – Joins multiple strings together.

    Example:

    SELECT CONCAT(category, ' - Pizza') AS pizza_category FROM pizza_type;

    Result:

    categorypizza_category
    ClassicClassic - Pizza

Date and Time Functions

Snowflake has functions for handling dates and times.

  • CURRENT_DATE – Returns today’s date.
  • CURRENT_TIME – Returns the current time.
  • EXTRACT – Retrieves specific parts (year, month, day) from a date or timestamp.

Example:

SELECT EXTRACT(MONTH FROM order_date) AS order_month FROM orders;

Result:

order_dateorder_month
2024-03-063

Sorting and Grouping

Sorting and grouping work similarly to PostgreSQL.

  • ORDER BY – Sorts query results.
  • GROUP BY – Groups data based on specified columns.
  • GROUP BY ALL – Groups by all selected columns without listing them individually.

Example:

SELECT pizza_type_id, size, AVG(price) AS avg_price 
FROM pizzas
GROUP BY ALL;