<<<<<<< HEAD current_user | H2 | SQLDoc
Skip to main content

current_user

1. CURRENT_USER Function

======= current_user | H2 Function | SQLDoc

current_user

1. CURRENT_USER Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The CURRENT_USER function in H2 database is used to retrieve the current username.

2. Syntax

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

CURRENT_USER()

Arguments

  • None

Return

  • The CURRENT_USER function returns the current username as a string.

3. Notes

  • The CURRENT_USER function in H2 database does not require any arguments.
  • It returns the username of the currently logged-in user executing the query.
  • The returned username may vary depending on the authentication mechanism used by the database.

4. Examples

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

Example 1 - Retrieving the current username:

SELECT CURRENT_USER() AS username;

Output:

username
--------
john

Example 2 - Using CURRENT_USER in a WHERE clause:

SELECT * 
FROM users
WHERE username = CURRENT_USER();

Output:

id | username |  email
---+----------+----------------
1 | john | john@example.com
  • USER - Retrieve the current username (deprecated in H2)