Return the current database name (synonym for CURRENT_CATALOG).
CURRENT_DATABASE()
## Overview Returns the name of the currently bound database for the session. DeltaForge treats the top level of the three-part hierarchy as both a 'catalog' and a 'database', depending on the SQL dialect in use, so CURRENT_DATABASE is a synonym for CURRENT_CATALOG. Use this function for PG-compat SQL that expects `current_database()` to exist. ## Session context - The value is the top-level namespace that the session is currently using. - Changes when the session switches catalog via `USE CATALOG` or equivalent. - Takes no arguments; both `CURRENT_DATABASE` and `CURRENT_DATABASE()` are accepted. - Never returns NULL. ## Behavior - Always returns a non-NULL string. - Deterministic for the duration of the current binding. - Side effect free. ## Compatibility - PG-compat alias for CURRENT_CATALOG; the two functions return the same value.
-- Read the active database name
SELECT CURRENT_DATABASE();
-- Include in a diagnostics report
SELECT CURRENT_DATABASE() AS db, VERSION() AS engine_version;
-- Conditional logic based on environment
SELECT CASE WHEN CURRENT_DATABASE() = 'production' THEN 'prod' ELSE 'non-prod' END AS env;
-- Fully qualify a table name
SELECT CURRENT_DATABASE() || '.analytics.events' AS fqn;