database_path
1. DATABASE_PATH Function
=======database_path
1. DATABASE_PATH Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe DATABASE_PATH function in H2 database is used to retrieve the path of the current database.
2. Syntax
The syntax for the DATABASE_PATH function in H2 database is as follows:
DATABASE_PATH()
Arguments
- This function does not take any arguments.
Return
- The DATABASE_PATH function returns the path of the current database as a string.
3. Notes
- The DATABASE_PATH function in H2 database is only applicable when working with a file-based database.
- If the current database is an in-memory database or a remote database, the function will return
NULL
. - Ensure that the database is properly initialized and connected before using the DATABASE_PATH function.
- The returned path may vary depending on the operating system and file system used.
4. Examples
Here are a few examples demonstrating the usage of the DATABASE_PATH function in H2 database:
Example 1 - Retrieving the path of the current database:
SELECT DATABASE_PATH();
Output:
DATABASE_PATH()
---------------
/home/user/mydatabase
Example 2 - Using the DATABASE_PATH function in a query:
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(50),
salary DOUBLE
);
INSERT INTO employees VALUES (1, 'John Doe', 50000), (2, 'Jane Smith', 60000);
SELECT * FROM employees WHERE DATABASE_PATH() = '/home/user/mydatabase';
Output:
id | name | salary
---+-----------+--------
1 | John Doe | 50000
2 | Jane Smith| 60000
5. Related Functions
There are no specific related functions for the DATABASE_PATH function in H2 database.