MCPcopy Create free account
hub / github.com/apache/cloudberry / pg_sequence_last_value

Function pg_sequence_last_value

src/backend/commands/sequence.c:2035–2068  ·  view source on GitHub ↗

* Return the last value from the sequence * * Note: This has a completely different meaning than lastval(). */

Source from the content-addressed store, hash-verified

2033 * Note: This has a completely different meaning than lastval().
2034 */
2035Datum
2036pg_sequence_last_value(PG_FUNCTION_ARGS)
2037{
2038 Oid relid = PG_GETARG_OID(0);
2039 SeqTable elm;
2040 Relation seqrel;
2041 Buffer buf;
2042 HeapTupleData seqtuple;
2043 Form_pg_sequence_data seq;
2044 bool is_called;
2045 int64 result;
2046
2047 /* open and lock sequence */
2048 init_sequence(relid, &elm, &seqrel);
2049
2050 if (pg_class_aclcheck(relid, GetUserId(), ACL_SELECT | ACL_USAGE) != ACLCHECK_OK)
2051 ereport(ERROR,
2052 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2053 errmsg("permission denied for sequence %s",
2054 RelationGetRelationName(seqrel))));
2055
2056 seq = read_seq_tuple(seqrel, &buf, &seqtuple);
2057
2058 is_called = seq->is_called;
2059 result = seq->last_value;
2060
2061 UnlockReleaseBuffer(buf);
2062 relation_close(seqrel, NoLock);
2063
2064 if (is_called)
2065 PG_RETURN_INT64(result);
2066 else
2067 PG_RETURN_NULL();
2068}
2069
2070
2071void

Callers

nothing calls this directly

Calls 8

init_sequenceFunction · 0.85
pg_class_aclcheckFunction · 0.85
GetUserIdFunction · 0.85
read_seq_tupleFunction · 0.85
UnlockReleaseBufferFunction · 0.85
relation_closeFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected