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

readonly

1. READONLY Function

======= readonly | H2 Function | SQLDoc

readonly

1. READONLY Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The READONLY function in H2 database is used to check if a table is read-only or not.

2. Syntax

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

READONLY(table_name)

Argument

  • table_name: The name of the table that you want to check if it is read-only. It should be a valid table name.

Return

  • The READONLY function returns TRUE if the specified table is read-only, and FALSE if it is not.

3. Notes

  • The READONLY function in H2 database can be used to determine if a table is read-only or not.
  • The function will return FALSE for regular tables that allow modifications, and TRUE for system tables or views that are read-only.
  • It is important to ensure that the table name provided to the READONLY function exists in the database, otherwise an error will be thrown.
  • The READONLY function can be useful in scenarios where you want to check the accessibility and permissions of a table before performing any modifications on it.

4. Examples

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

Example 1 - Checking if a table is read-only:

CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(50)
);

CREATE VIEW readonly_employees AS SELECT * FROM employees;

SELECT READONLY('employees') AS is_readonly_employees,
READONLY('readonly_employees') AS is_readonly_view;

Output:

is_readonly_employees | is_readonly_view
----------------------+-----------------
FALSE | TRUE

Example 2 - Using READONLY in a conditional statement:

CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(50),
readonly BOOLEAN
);

INSERT INTO products VALUES (1, 'Product 1', FALSE),
(2, 'Product 2', TRUE);

SELECT id, name,
CASE WHEN READONLY('products') THEN 'Read-only' ELSE 'Writable' END AS access_status
FROM products;

Output:

id |   name    | access_status
---+-----------+---------------
1 | Product 1 | Writable
2 | Product 2 | Read-only

There are no related functions specifically for the READONLY function in H2 database.