Skip to main content

current_catalog

1. CURRENT_CATALOG Function

The CURRENT_CATALOG function in H2 database is used to retrieve the name of the current catalog (database) in use.

2. Syntax

The syntax for the CURRENT_CATALOG function in H2 database is as follows:

CURRENT_CATALOG()

Arguments

  • This function does not accept any arguments.

Return

  • The CURRENT_CATALOG function returns the name of the current catalog (database) as a string.

3. Notes

  • The CURRENT_CATALOG function in H2 database is useful when working with multiple catalogs (databases) within the same session.
  • If no catalog (database) has been explicitly set, this function returns the default catalog of the current session.
  • The name of the current catalog is returned as a string, so it can be used in other SQL statements or queries.

4. Examples

Here are a few examples demonstrating the usage of the CURRENT_CATALOG function in H2 database:

Example 1 - Retrieving the current catalog:

SELECT CURRENT_CATALOG() AS current_catalog;

Output:

current_catalog
----------------
PUBLIC

Example 2 - Using the current catalog in a query:

SELECT * FROM CURRENT_CATALOG()..EMPLOYEES;

Output:

+------+------------+---------+
| ID | NAME | SALARY |
+------+------------+---------+
| 1 | John Smith | 5000.0 |
| 2 | Jane Doe | 6000.0 |
+------+------------+---------+
  • current_schema - Retrieve the name of the current schema.
  • DATABASE - Retrieve the name of the current database (catalog).
  • SCHEMA - Retrieve the name of the current schema.