---
title: "currval()"
url: "https://docs.yugabyte.com/stable/api/ysql/exprs/sequence_functions/func_currval/"
---

# currval()

Returns the last value returned by the nextval() function for the specified sequence in the current session.

## Synopsis

Use the `currval( sequence_name )` function to return the last value returned by the `nextval( sequence_name )` function for the specified sequence in the current session.

## Semantics

### *sequence\_name*

Specify the name of the sequence.

- An error is raised if `nextval( sequence_name )` has not been called for the specified sequence in the current session.

## Examples

### Create a sequence

```plpgsql
yugabyte=# CREATE SEQUENCE s;
```

```output
CREATE SEQUENCE
```

Call `nextval()`:

```plpgsql
yugabyte=# SELECT nextval('s');
```

```output
 nextval
---------
       1
(1 row)
```

```plpgsql
yugabyte=# SELECT currval('s');
```

```output
 currval
---------
       1
(1 row)
```

Call `currval()` before `nextval()` is called.

```plpgsql
yugabyte=# CREATE SEQUENCE s2;
```

```output
CREATE SEQUENCE
```

```plpgsql
SELECT currval('s2');
```

```output
ERROR:  currval of sequence "s2" is not yet defined in this session
```

## See also

- [`CREATE SEQUENCE`](/stable/api/ysql/the-sql-language/statements/ddl_create_sequence "CREATE SEQUENCE")
- [`DROP SEQUENCE`](/stable/api/ysql/the-sql-language/statements/ddl_drop_sequence/ "DROP SEQUENCE")
