A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/functions-context below:

Website Navigation


Context functions | Snowflake Documentation

Context functions

This family of functions allows for the gathering of information about the context in which the statement is executed. These functions are evaluated at most once per statement.

List of functions Usage notes Examples

Display the current warehouse, database, and schema for the session:

SELECT CURRENT_WAREHOUSE(), CURRENT_DATABASE(), CURRENT_SCHEMA();

Copy

+---------------------+--------------------+------------------+
| CURRENT_WAREHOUSE() | CURRENT_DATABASE() | CURRENT_SCHEMA() |
|---------------------+--------------------+------------------+
| MY_WAREHOUSE        | MY_DB              | PUBLIC           |
|---------------------+--------------------+------------------+

Display the current date, time, and timestamp (note that parentheses are not required to call these functions):

SELECT CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP;

Copy

+--------------+--------------+-------------------------------+
| CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP             |
|--------------+--------------+-------------------------------|
| 2024-06-07   | 10:45:15     | 2024-06-07 10:45:15.064 -0700 |
+--------------+--------------+-------------------------------+

In a Snowflake Scripting block, call the CURRENT_DATE function without parentheses to set a variable in a SQL statement:

EXECUTE IMMEDIATE
$$
DECLARE
  currdate DATE;
BEGIN
  SELECT CURRENT_DATE INTO currdate;
  RETURN currdate;
END;
$$
;

Copy

+-----------------+
| anonymous block |
|-----------------|
| 2024-06-07      |
+-----------------+

In a Snowflake Scripting block, attempting to set a variable to an expression that calls the CURRENT_DATE function without parentheses results in an error:

EXECUTE IMMEDIATE
$$
DECLARE
  today DATE;
BEGIN
  today := CURRENT_DATE;
  RETURN today;
END;
$$
;

Copy

000904 (42000): SQL compilation error: error line 5 at position 11
invalid identifier 'CURRENT_DATE'

The same block returns the current date when the function is called with the parentheses:

EXECUTE IMMEDIATE
$$
DECLARE
  today DATE;
BEGIN
  today := CURRENT_DATE();
  RETURN today;
END;
$$
;

Copy

+-----------------+
| anonymous block |
|-----------------|
| 2024-06-07      |
+-----------------+

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4