---
title: "Information functions"
description: "CoraDB information functions: CURRENT_USER, DATABASE, VERSION, CHARSET, COLLATION, LAST_INSERT_ID, ROW_COUNT, DISK_SIZE and more."
url: "https://www.coradb.ai/manual/sql/function/information_fn.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/function/information_fn.md"
product: "CoraDB"
version: "1.0"
keywords: "information functions, charset, collation, coercibility, current_user, system_user, database, schema, dbtimezone, sessiontimezone, default, disk_size, index_cardinality, inet_aton, inet_ntoa, last_insert_id, row_count, list_dbs, version, label, property_of, coradb"
---

# Information functions

Information functions return facts about values, the session, the database and the server, rather than computing on data.

> **Try it yourself:**
> The examples run on the [e-commerce sample database](https://www.coradb.ai/manual/sample-database.html), connected as `dba`. Results that depend on your server, such as time zones and the database list, will differ.


## CHARSET

```text
CHARSET(expr)
```

Returns the character set of a string expression. **Return type:** VARCHAR.

## COLLATION

```text
COLLATION(expr)
```

Returns the collation of a string expression. **Return type:** VARCHAR.

```sql
SELECT CHARSET('abc'), CHARSET(_utf8'abc'), COLLATION('abc'), COLLATION(_utf8'abc') FROM db_root;
```

| charset('abc') | charset(_utf8'abc') | collation('abc') | collation(_utf8'abc') |
|---|---|---|---|
| utf8 | utf8 | utf8_bin | utf8_bin |

## COERCIBILITY

```text
COERCIBILITY(expr)
```

Returns the collation coercibility level of an expression: when two expressions with different collations meet, the one with the lower level decides the collation of the result. For the levels, see [Collation coercibility](https://www.coradb.ai/manual/sql/i18n_collation.html#collation-coercibility). **Return type:** INT.

```sql
SELECT COERCIBILITY(USER()), COERCIBILITY('abc'), COERCIBILITY(name)
FROM countries WHERE code = 'FRA';
```

| coercibility( user() ) | coercibility('abc') | coercibility(name) |
|---:|---:|---:|
| 7 | 10 | 3 |

A column (3) wins over a function result (7), which wins over a constant (10).


## CURRENT_USER, USER

```text
CURRENT_USER
USER
```

Pseudocolumns that return the name of the user of the current session. **Return type:** VARCHAR.


## USER(), SYSTEM_USER()

```text
USER()
SYSTEM_USER()
```

Return the current user name followed by a host name, as `user@host`. **Return type:** VARCHAR.

```sql
SELECT CURRENT_USER, USER(), SYSTEM_USER() FROM db_root;
```

```text
DBA    DBA@db-server-01    DBA@db-server-01
```

The users of the database are listed in the `db_user` catalog view.


## DATABASE, SCHEMA

```text
DATABASE()
SCHEMA()
```

Return the name of the database the session is connected to. The two functions are the same. **Return type:** VARCHAR.

```sql
SELECT DATABASE(), SCHEMA() FROM db_root;
```

| database() | schema() |
|---|---|
| e-commerce | e-commerce |

## DBTIMEZONE

```text
DBTIMEZONE()
```

Returns the time zone of the database server, as an offset (`'-05:00'`) or a region name (`'Europe/Vienna'`). **Return type:** VARCHAR.

## SESSIONTIMEZONE

```text
SESSIONTIMEZONE()
```

Returns the time zone of the current session, which applies to `TIMESTAMP WITH LOCAL TIME ZONE` and `DATETIME WITH LOCAL TIME ZONE` values. It is the server's time zone unless the session changed it. **Return type:** VARCHAR.

```sql
SELECT DBTIMEZONE(), SESSIONTIMEZONE() FROM db_root;
```

```text
Europe/Bucharest    Europe/Bucharest
```

See also [FROM_TZ](https://www.coradb.ai/manual/sql/function/datetime_fn.html#from_tz), [NEW_TIME](https://www.coradb.ai/manual/sql/function/datetime_fn.html#new_time), [TZ_OFFSET](https://www.coradb.ai/manual/sql/function/datetime_fn.html#tz_offset) and the [timezone parameters](https://www.coradb.ai/manual/admin/config_sql.html#timezone-parameter).

## DEFAULT

```text
DEFAULT
DEFAULT(column_name)
```

`DEFAULT(column_name)` returns the default value defined for a column. If the column has no default, the result is `NULL`; for a `NOT NULL` or `PRIMARY KEY` column without a default, it is an error. The keyword `DEFAULT` on its own stands for the column's default value in `INSERT` and `UPDATE` statements.

```sql
CREATE TABLE info_tbl (id INT DEFAULT 0, name VARCHAR(10));
INSERT INTO info_tbl VALUES (1, 'a'), (2, 'b'), (NULL, 'c');

SELECT id, DEFAULT(id) FROM info_tbl ORDER BY name;
```

| id | default(id) |
|---:|---:|
| 1 | 0 |
| 2 | 0 |
| NULL | 0 |

```sql
UPDATE info_tbl SET id = DEFAULT WHERE id IS NULL;
DELETE FROM info_tbl WHERE id = DEFAULT(id);
INSERT INTO info_tbl VALUES (DEFAULT, 'd');
```


## DISK_SIZE

```text
DISK_SIZE(expr)
```

Returns the number of bytes needed to store the value of *expr* in a table, taking [string compression](https://www.coradb.ai/manual/sql/datatype_string.html#string_compression) into account. Use it to estimate the storage a column needs. **Return type:** INT.

```sql
SELECT DISK_SIZE(name), DISK_SIZE(description), DISK_SIZE(unit_price), DISK_SIZE(id)
FROM product WHERE id = 1795;
```

| disk_size(name) | disk_size(description) | disk_size(unit_price) | disk_size(id) |
|---:|---:|---:|---:|
| 24 | 16 | 16 | 4 |

For constants: `DISK_SIZE('abc')` is 7 and `DISK_SIZE(1)` is 4.

## INDEX_CARDINALITY

```text
INDEX_CARDINALITY(table_name, index_name, key_pos)
```

Returns the number of distinct keys in an index, as recorded in the statistics. *key_pos* selects the key prefix: 0 counts distinct values of the first column, 1 of the first two columns, and so on. Run [UPDATE STATISTICS](https://www.coradb.ai/manual/sql/tuning.html) first for current figures.

- *table_name*, *index_name*: strings.
- *key_pos*: an integer, or a value that can be converted to one (`FLOAT` and `DOUBLE` values are rounded).

**Return type:** INT. The result is `NULL` if an argument is `NULL`, if the table or index does not exist, or if *key_pos* is out of range.

The primary key of `order_items` is `(order_id, product_id)`:

```sql
SELECT INDEX_CARDINALITY('order_items', 'pk_order_items_order_id_product_id', 0),
       INDEX_CARDINALITY('order_items', 'pk_order_items_order_id_product_id', 1),
       INDEX_CARDINALITY('order_items', 'pk_order_items_order_id_product_id', 2)
FROM db_root;
```

| index_cardinality(..., 0) | index_cardinality(..., 1) | index_cardinality(..., 2) |
|---:|---:|---:|
| 11230 | 11230 | NULL |

## INET_ATON

```text
INET_ATON(ip_string)
```

Converts an IPv4 address `'a.b.c.d'` to the number a × 256³ + b × 256² + c × 256 + d. **Return type:** BIGINT.

## INET_NTOA

```text
INET_NTOA(number)
```

Converts a number back to an IPv4 address string. **Return type:** VARCHAR.

```sql
SELECT INET_ATON('192.168.0.10'), INET_NTOA(3232235530) FROM db_root;
```

| inet_aton('192.168.0.10') | inet_ntoa(3232235530) |
|---:|---|
| 3232235530 | 192.168.0.10 |

## LAST_INSERT_ID

```text
LAST_INSERT_ID()
```

Returns the `AUTO_INCREMENT` value generated by the most recent successful `INSERT` of the session. **Return type:** NUMERIC(38,0).

- After a multi-row `INSERT`, it returns the value generated for the **first** row.
- A value you insert yourself is not reported; only generated values are.
- A failed `INSERT` does not change it, but the `AUTO_INCREMENT` counter may still have advanced, so the next value can skip numbers.
- A rollback does not reset it.
- Each session has its own value. A value generated inside a trigger is not visible outside the trigger.

```sql
CREATE TABLE ai (a INT PRIMARY KEY AUTO_INCREMENT, b INT UNIQUE);

INSERT INTO ai VALUES (NULL, 1);
SELECT LAST_INSERT_ID();                                   -- 1

INSERT INTO ai VALUES (NULL, 11), (NULL, 12), (NULL, 13);
SELECT LAST_INSERT_ID();                                   -- 2, the first of 2, 3, 4

INSERT INTO ai VALUES (500, 20), (NULL, 21);
SELECT LAST_INSERT_ID();                                   -- 5: 500 was given, not generated
```

See also [AUTO_INCREMENT](https://www.coradb.ai/manual/sql/schema/table_stmt.html#auto-increment).

## ROW_COUNT

```text
ROW_COUNT()
```

Returns the number of rows changed by the last `INSERT`, `UPDATE` or `DELETE` statement of the session. **Return type:** INT.

```sql
CREATE TABLE rc (i INT);
INSERT INTO rc VALUES (1), (2), (3), (4), (5), (6), (7);
SELECT ROW_COUNT();                 -- 7
UPDATE rc SET i = 0 WHERE i > 3;
SELECT ROW_COUNT();                 -- 4
DELETE FROM rc WHERE i = 0;
SELECT ROW_COUNT();                 -- 4
```

## LIST_DBS

```text
LIST_DBS()
```

Returns the names of all databases in the database location file (`databases.txt`), separated by spaces. **Return type:** VARCHAR.

```sql
SELECT LIST_DBS() FROM db_root;
```

```text
chinook e-commerce healthcare movie-lens nba2014-2015 northwind northwind-rel olympics1988-2004 sakila star-wars
```

## VERSION

```text
VERSION()
```

Returns the version of the CoraDB server, for example `1.0.0.1586`. **Return type:** VARCHAR.

## LABEL

```text
LABEL(graph_element)
```

Returns the label of a vertex or edge, that is, the name of its vertex or edge table. Use it in [MATCH](https://www.coradb.ai/manual/graph/match.html) queries to tell which table a matched element belongs to. **Return type:** VARCHAR.

```sql
SELECT LABEL(b), LABEL(m), LABEL(p)
FROM MATCH (b:brand)-[m:manufactures]->(p:product)
WHERE p.id = 1795;
```

| label(b) | label(m) | label(p) |
|---|---|---|
| brand | manufactures | product |

The argument must be a graph element; `LABEL('text')` is an error (`Incompatible argument type char, expected type is: object`).


## PROPERTY_OF

```text
PROPERTY_OF(graph_element, property_name, table_name)
```

Returns one property (column) of a vertex or edge. It is mainly used with the path functions [NODES](https://www.coradb.ai/manual/sql/function/graph_fn.html), [RELATIONSHIPS](https://www.coradb.ai/manual/sql/function/graph_fn.html), [FIRST](https://www.coradb.ai/manual/sql/function/list_fn.html) and [LAST](https://www.coradb.ai/manual/sql/function/list_fn.html), which return graph elements rather than rows of a known table.

- *graph_element*: a vertex or edge.
- *property_name*: the column to return, written as an identifier.
- *table_name*: the vertex or edge table that defines the column. When several tables have a column with that name, it says which one is meant.

**Return type:** the type of the column.

The first and last vertex of each path from customer 5 to the products it likes:

```sql
SELECT PROPERTY_OF(FIRST(NODES(pth)), company_name, customer) AS customer,
       PROPERTY_OF(LAST(NODES(pth)), name, product) AS product
FROM MATCH pth = (c:customer)-[:likes]->(p:product)
WHERE c.id = 5
ORDER BY 2;
```

| customer | product |
|---|---|
| Brown, Roman and Allen | Circe Hooded Ice Fleece |
| Brown, Roman and Allen | Sirop derable |
| Brown, Roman and Allen | Sybil Running Short |

## See also

- [Graph functions](https://www.coradb.ai/manual/sql/function/graph_fn.html)
- [String functions](https://www.coradb.ai/manual/sql/function/string_fn.html)
