# Session functions

> Connection identity, selected database, named locks and statement state.

---

LLMS index: [llms.txt](/llms.txt)

---

Connection identity, selected database, named locks and statement state.

## connection_id {#connection_id}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-connection-id-02cf0605" href="#mysql-connection-id-02cf0605">`mysql.connection_id() → bigint`</a> | Return the PostgreSQL backend PID for this connection. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L130-L131) |

## current_user {#current_user}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-current-user-ebe52fe9" href="#mysql-current-user-ebe52fe9">`mysql."current_user"() → text`</a> | Effective PostgreSQL role formatted as role@%. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L120-L123) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mysm/user.c#L22-L38) |

## database {#database}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-database-f727e295" href="#mysql-database-f727e295">`mysql.database() → text`</a> | Return the MySQL database selected in this session. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L63-L66) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mys_compat.c#L110-L133) |

## found_rows {#found_rows}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-found-rows-82106f3b" href="#mysql-found-rows-82106f3b">`mysql.found_rows() → bigint`</a> | Read the session’s found-row count. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L105-L108) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mysm/strfuncs.c#L1355-L1359) |

## get_lock {#get_lock}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-get-lock-pg-catalog-any-pg-catalog-any-af36de9b" href="#mysql-get-lock-pg-catalog-any-pg-catalog-any-af36de9b">`mysql.get_lock("any", "any") → bigint`</a> | Acquire a named session lock with a timeout. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L30-L33) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mys_lock.c#L495-L519) |

## is_free_lock {#is_free_lock}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-is-free-lock-pg-catalog-any-ab3f9f21" href="#mysql-is-free-lock-pg-catalog-any-ab3f9f21">`mysql.is_free_lock("any") → bigint`</a> | Check whether a named lock is available. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L40-L43) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mys_lock.c#L548-L559) |

## is_used_lock {#is_used_lock}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-is-used-lock-pg-catalog-any-4cb80c4b" href="#mysql-is-used-lock-pg-catalog-any-4cb80c4b">`mysql.is_used_lock("any") → bigint`</a> | Look up the holder of a named lock. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L45-L48) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mys_lock.c#L562-L577) |

## last_insert_id {#last_insert_id}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-last-insert-id-52a135f5" href="#mysql-last-insert-id-52a135f5">`mysql.last_insert_id() → bigint`</a> | Read the session’s last generated insert ID. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L110-L113) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mysm/strfuncs.c#L1362-L1366) |

## release_all_locks {#release_all_locks}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-release-all-locks-2039902e" href="#mysql-release-all-locks-2039902e">`mysql.release_all_locks() → bigint`</a> | Release all named locks held by this session. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L50-L53) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mys_lock.c#L607-L611) |

## release_lock {#release_lock}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-release-lock-pg-catalog-any-188c9cdf" href="#mysql-release-lock-pg-catalog-any-188c9cdf">`mysql.release_lock("any") → bigint`</a> | Release a named session lock. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L35-L38) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mys_lock.c#L525-L545) |

## row_count {#row_count}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-row-count-d2566d6f" href="#mysql-row-count-d2566d6f">`mysql.row_count() → bigint`</a> | Read the affected-row count for the previous statement. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L100-L103) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mysm/strfuncs.c#L1348-L1352) |

## schema {#schema}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-schema-fd365ee7" href="#mysql-schema-fd365ee7">`mysql.schema() → text`</a> | Return the MySQL database selected in this session. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L68-L71) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mys_compat.c#L110-L133) |

## session_user {#session_user}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-session-user-59992dbc" href="#mysql-session-user-59992dbc">`mysql."session_user"() → text`</a> | Session role and client host. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L125-L128) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mysm/user.c#L41-L59) |

## sleep {#sleep}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-sleep-numeric-88311da1" href="#mysql-sleep-numeric-88311da1">`mysql.sleep(seconds numeric) → character varying`</a> | Wait for the requested number of seconds. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L6-L17) |

## user {#user}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-user-38884724" href="#mysql-user-38884724">`mysql."user"() → text`</a> | Return PostgreSQL current_user as text. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L55-L61) |

## uuid {#uuid}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-uuid-c9833996" href="#mysql-uuid-c9833996">`mysql.uuid() → text`</a> | Generate a UUID. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L19-L27) |

## uuid_short {#uuid_short}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-uuid-short-4c578abe" href="#mysql-uuid-short-4c578abe">`mysql.uuid_short() → text`</a> | Generate a short MySQL-style identifier. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L115-L118) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mysm/uuid_short.c#L21-L29) |

## version {#version}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-version-4bb1f911" href="#mysql-version-4bb1f911">`mysql.version() → text`</a> | Return the advertised MySQL server version. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/46-func-sess.sql#L73-L76) · [C](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/src/mysm/strfuncs.c#L1434-L1440) |

---

Backlinks:

- [Functions](/docs/mysql/reference/objects/functions/)
