AWS Security ChangesHomeSearch

AWS aurora-dsql: Clarify currval/lastval transaction semantics and sequence gaps

Service: aurora-dsql · 2026-11-07 · Documentation low

File: aurora-dsql/latest/userguide/sequence-functions-syntax-support.md

Summary

Rewrites the currval and lastval descriptions to state they are only reliable within the same transaction as nextval, adds guidance to use nextval's return value or INSERT ... RETURNING for exact values, and converts the sequence-gap note into a Warning.

Security assessment

The change is a correctness/semantics clarification for sequence functions (transaction-scoped values, non-gapless sequences). The only privilege mention (USAGE/SELECT on the sequence) is pre-existing context, not new security guidance, so this is a non-security documentation edit.

Evidence

+Call `currval` or `lastval` in the same transaction as `nextval`. Across transaction boundaries, their results are nondeterministic. Either function might return an error or a value from another transaction.

Diff

diff --git a/aurora-dsql/latest/userguide/sequence-functions-syntax-support.md b/aurora-dsql/latest/userguide/sequence-functions-syntax-support.md
index 248dd03..4b5d722 100644
--- a//aurora-dsql/latest/userguide/sequence-functions-syntax-support.md
+++ b//aurora-dsql/latest/userguide/sequence-functions-syntax-support.md
@@ -28,2 +28,2 @@ The result returned by `setval` is just the value of its second argument. This f
-`currval ( regclass ) → bigint` | Returns the value most recently obtained by `nextval` for this sequence in the current session. (An error is reported if `nextval` has never been called for this sequence in this session.) Because this is returning a session-local value, it gives a predictable answer whether or not other sessions have run `nextval` because the current session did. This function requires `USAGE` or `SELECT` privilege on the sequence.  
-`lastval () → bigint` | Returns the value most recently returned by `nextval` in the current transaction. This function is identical to `currval`, except that instead of taking the sequence name as an argument it refers to whichever sequence `nextval` was most recently applied to in the current transaction. It's an error to call `lastval` if `nextval` hasn't yet been called in the current transaction. This function requires `USAGE` or `SELECT` privilege on the last used sequence.  
+`currval ( regclass ) → bigint` | When called after `nextval` in the same transaction, returns the value most recently returned by `nextval` for this sequence. This function requires `USAGE` or `SELECT` privilege on the sequence.  
+`lastval () → bigint` | When called after `nextval` in the same transaction, returns the value most recently returned by `nextval`. This function is identical to `currval`, except that instead of taking the sequence name as an argument it refers to whichever sequence `nextval` was most recently applied to. This function requires `USAGE` or `SELECT` privilege on the last used sequence.  
@@ -33 +33,7 @@ The result returned by `setval` is just the value of its second argument. This f
-The value obtained by `nextval` isn't reclaimed for re-use if the calling transaction later aborts. This means that transaction aborts or database crashes can result in gaps in the sequence of assigned values. That can happen without a transaction abort, too. For example, an `INSERT` with an `ON CONFLICT` clause will compute the to-be-inserted tuple, including doing any required `nextval` calls, before detecting any conflict that would cause it to follow the `ON CONFLICT` rule instead. Thus, Aurora DSQL's sequence objects _can't be used to obtain "gapless" sequences_.
+Call `currval` or `lastval` in the same transaction as `nextval`. Across transaction boundaries, their results are nondeterministic. Either function might return an error or a value from another transaction.
+
+If your application requires the exact value assigned by a sequence, use the value returned by `nextval` directly. For values generated during an `INSERT`, use `INSERT ... RETURNING`.
+
+###### Warning
+
+The value obtained by `nextval` isn't reclaimed for re-use if the calling transaction later aborts. This can result in gaps in the sequence of assigned values. Gaps can also occur without a transaction abort. For example, an `INSERT` with an `ON CONFLICT` clause computes the row to insert, including any required `nextval` calls, before it detects a conflict. When the command follows the `ON CONFLICT` action, Aurora DSQL doesn't reclaim the sequence value.